home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / kcl_txt.lha / kcl-report.doc < prev    next >
Text File  |  1993-08-13  |  231KB  |  5,833 lines

  1.   
  2.                          Kyoto Common Lisp Report
  3.  
  4.                       Taiichi Yuasa and Masami Hagiya
  5.  
  6.       Research Institute for Mathematical Sciences, Kyoto University
  7.  
  8.          Copyright (c) 1985 by the authors.  All rights reserved.
  9.  
  10.  
  11.  
  12.                                   Preface
  13.  
  14. Kyoto Common Lisp (KCL for short) is a full implementation of the Common
  15. Lisp language described in the Common Lisp Reference Manual:
  16.  
  17.  
  18.                Common Lisp: The Language.
  19.                by Guy L. Steele et al.
  20.                Digital Press, 1984
  21.  
  22. All Common Lisp functions, macros, and special forms are defined in KCL,
  23. though a few of them have slightly different meanings from those described
  24. in the Common Lisp Reference Manual.  All such differences are described in
  25. this report:  If a Common Lisp function (or macro or special form) does not
  26. work as described in the Common Lisp Reference Manual and if this report
  27. does not describe the difference explicitly, then there must be a bug in
  28. KCL.  All Common Lisp variables and constants are defined in KCL exactly as
  29. described in the Common Lisp Reference Manual.
  30.  
  31.      Currently, there are four major versions of KCL:
  32.  
  33.         1. KCL/AOS, under the AOS/VS operating system for
  34.            Data General's ECLIPSE MV series machines.
  35.  
  36.         2. KCL/VAX, under the Unix 4.2 bsd operating system for
  37.            Digital Equipment Corporation's VAX 11 series machines.
  38.  
  39.         3. KCL/SUN, under the Unix 4.2 bsd operating system for
  40.            Sun Microsystems' Sun Workstation.
  41.  
  42.         4. KCL/UST, under the Unix V (Uniplus' version)
  43.            operating system for Sumitomo Electric Industries and
  44.            Digital Computer Laboratory's Ustation E15.
  45.  
  46. KCL/AOS is the original version of KCL, which was developed at the Research
  47. Institute for Mathematical Sciences (RIMS), Kyoto University, with the
  48. cooperation of Nippon Data General Corporation.  The other three versions,
  49. which are collectively called KCL on Unix, are transplanted versions of
  50. KCL/AOS.
  51.  
  52.      This report is intended to complement the Common Lisp Reference
  53. Manual.  This report describes deviations of KCL from Common Lisp, those
  54. features specific to KCL, and the implementation-dependent functions of
  55. Common Lisp.
  56.  
  57.  
  58.  
  59.                       Acknowledgements
  60.  
  61.  
  62. The project of KCL was supported by many people affiliated with many
  63. institutions.  We are very grateful especially to the following people for
  64. their contributions to the KCL project.
  65.  
  66.      First of all, we are grateful to the contributors to the design of
  67. Common Lisp.
  68.  
  69.      Prof. Reiji Nakajima at RIMS, Kyoto University, provided us with
  70. considerable encouragement and moral support.
  71.  
  72.      Nippon Data General Corporation (NDG) helped us implement KCL/AOS.
  73. Mr. Teruo Yabe and Mr. Toshiyasu Harada joined us during the first stage of
  74. the KCL project and did a lot of coding.  Mr. Takashi Suzuki and Mr. Kibo
  75. Kurokawa arranged the joint project.  NDG is now supporting the
  76. distribution of KCL/AOS.
  77.  
  78.      Data General Corporation in the United States sent us materials
  79. necessary to implement a Common Lisp system, such as the preliminary drafts
  80. of the Common Lisp reference manual and benchmark tests for Common Lisp.
  81.  
  82.  For the benchmark tests we are indebted to Dr. Richard Gabriel at
  83. Stanford University.
  84.  
  85.      Dr. Daniel Weinreb at Symbolics answered most of our questions about
  86. the language specification.  He also sent us the definition of r a t i o n
  87. a l i z e written by Dr. Skef Wholey at CMU.  We use this definition in KCL
  88. without any change.
  89.  
  90.      Dr. Carl Hoffman at Symbolics checked the top-level of KCL and gave us
  91. advice for improving KCL.  He also found some bugs in KCL and fixed them
  92. for us.
  93.  
  94.      Mr. Naruhiko Kawamura at RIMS developed a Prolog system using the
  95. earliest version of KCL/AOS.  That was one of the first big projects with
  96. KCL and he found many bugs.
  97.  
  98.      Mr. Takashi Sakuragawa at RIMS hacked with KCL/AOS and gave us much
  99. advice concerning those features specific to KCL.
  100.  
  101.      Mr. Tatsuya Hagino at Edinburgh University developed Micro EMACS on
  102. which FeCl2, the full-screen editor embedded in KCL/AOS, is based.
  103.  
  104.      Mr. Kunihiko Nakamura at Kagawa University converted the assembly
  105. language version of Micro EMACS into the C language, which happened to
  106. become the prototype of FeCl2.
  107.  
  108.      Prof. Akinori Yonezawa at Tokyo Institute of Technology encouraged us
  109. to port KCL/AOS to the VAX 11.
  110.  
  111.      Mr. Etsuya Shibayama at Tokyo Institute of Technology helped us while
  112. we were working with the VAX 11 at the Institute.
  113.  
  114.      Hagiwara Laboratory at Kyoto University offered (and is offering)
  115. their VAX 11 for finishing transplantation and maintaining KCL/VAX.  We got
  116. also technical advice from people at Hagiwara Laboratory.
  117.  
  118.      Prof. Shuji Doshita at Kyoto University offered the SUN Workstation at
  119. his Laboratory and gave us a lot of advice for transplantation to the SUN
  120. Workstation.
  121.  
  122.      Mr. Takashi Hattori at RIMS gave us useful information about the
  123. Motorola 68000, the CPU chip of SUN Workstation.
  124.  
  125.      NDG helped us build up the KROFF (K yoto ROFF) system, with which this
  126. report was produced.  They offered the character font sets from which the
  127. font sets used in KROFF were constructed.  We also received some technical
  128. advice from NDG about the output device of KROFF, i.e., NDG's 5880 series
  129. laser beam printers.  Incidentally, all the programs that constitute the
  130. KROFF system, including tools to maintain KROFF font sets, are written in
  131. the Common Lisp language and are running under KCL.
  132.  
  133.  
  134.  
  135.  
  136.                             Table of Contents
  137.  
  138.  
  139.  Preface
  140.  Acknowledgements
  141.  Table of Contents
  142.  
  143.  Chapter 1. How to Start and End a KCL Session
  144.  
  145.  Chapter 2. Data Types
  146.           2.1. Numbers
  147.           2.1.1. Integers
  148.           2.1.2. Ratios
  149.           2.1.3. Floating-point Numbers
  150.           2.1.4. Complex Numbers
  151.         2.2. Characters
  152.           2.2.1. Standard Characters
  153.           2.2.2. Line Divisions
  154.           2.2.3. Non-standard Characters
  155.           2.2.4. Character Attributes
  156.           2.2.5. String Characters
  157.         2.3. Symbols
  158.         2.4. Lists and Conses
  159.         2.5. Arrays
  160.           2.5.1. Vectors
  161.           2.5.2. Strings
  162.           2.5.3. Bit-Vectors
  163.         2.6. Hash Tables
  164.         2.7. Readtables
  165.         2.8. Packages
  166.         2.9. Pathnames
  167.         2.10. Streams
  168.         2.11. Random-States
  169.         2.12. Structures
  170.         2.13. Functions
  171.         2.14. Unreadable Data Objects
  172.         2.15. Overlap, Inclusion, and Disjointness of Types
  173.  
  174.  Chapter 3. Input and Output
  175.         3.1. Read Macros
  176.         3.2. Input and Output Functions
  177.  
  178.  Chapter 4. Memory Management
  179.         4.1. Implementation Types
  180.         4.2. Heap and Relocatable Areas
  181.         4.3. The Garbage Collector
  182.         4.4. Allocation Functions
  183.         4.5. Storage Information
  184.  
  185.  Chapter 5. Debugging Facilities
  186.         5.1. The Tracer
  187.         5.2. The Stepper
  188.         5.3. Errors
  189.         5.4. The Break Loop
  190.         5.5. Describe and Inspect
  191.  
  192.  Chapter 6. The Compiler
  193.  
  194.  Chapter 7. Declarations
  195.         7.1. Declaration Specifiers
  196.         7.2. Significant Type Specifiers
  197.         7.3. Treatment of Type Declarations
  198.           7.3.1. Variable Allocations
  199.           7.3.2. Built-in Functions that Operate on Raw Data Directly
  200.           7.3.3. Arguments/Values Passing
  201.  
  202.  Chapter 8. Operating System Interface
  203.  
  204.  Chapter 9. Macros
  205.         9.1. System Macros
  206.         9.2. Defmacro Lambda-Lists
  207.  
  208.  Chapter 10. The C Language Interface
  209.  
  210.  Chapter 11. The Editor
  211.  
  212.  Appendix A. KCL Summary
  213.  
  214.  Appendix B. An Overview of Kyoto Common Lisp
  215.  
  216.  Appendix C. Kyoto Common Lisp Installation Guide
  217.         C.1. Installation of KCL/AOS
  218.         C.2. Installation of KCL/VAX
  219.         C.3. Installation of KCL/SUN
  220.         C.4. Installation of KCL/UST
  221.  
  222.  
  223.  
  224.  
  225.              Chapter 1. How to Start and End a KCL Session
  226.  
  227.  
  228. KCL on Unix is invoked by the Shell command  kcl.
  229.  
  230.         % kcl
  231.         KCL (Kyoto Common Lisp)  July 1, 1987
  232.  
  233.  
  234. ---------------------- Note to KCL/AOS users ----------------------
  235.  
  236. KCL/AOS is invoked by the CLI command  KCL.
  237.  
  238.         ) KCL
  239.         KCL (Kyoto Common Lisp)   July 1, 1987
  240.  
  241. --------------------------- End of Note ----------------------------
  242.  
  243.  
  244. When invoked, KCL will print the banner and initialize the system.
  245. The date in the KCL banner identifies the revision of KCL.  
  246. "July 1, 1987" is the value of the
  247. function   lisp-implementation-version.
  248.  
  249.      If there exists a file named init.lsp in the current working
  250. directory, KCL successively evaluates the forms in the file, immediately
  251. after the system initialization.  The user may set up his or her own KCL
  252. environment (e.g., the memory configuration) with
  253. init.lsp.
  254.  
  255.      After the initialization, KCL enters the top-level loop and prints the
  256. prompt '>'.
  257.  
  258.         >
  259.  
  260. The prompt indicates that KCL is now ready to receive a form from the
  261. terminal and to evaluate it.
  262.  
  263.      Usually, the current package (i.e., the value of *package*) is the
  264. user package, and the prompt appears as above.  If, however, the current
  265. package is other than the user package, then the prompt will be prefixed by
  266. the package name.
  267.  
  268.         package-name>
  269.  
  270.      To exit from KCL,
  271. call the function  bye (or by).
  272.  
  273.         >(bye)
  274.         Bye.
  275.         %
  276.  
  277.  
  278. ---------------------- Note to KCL/AOS users ----------------------
  279.  
  280. In this report, we sometimes assume that KCL is invoked from the Unix
  281. Shell.  In particular, we use the standard prompt of the Unix Shell '%' in
  282. most examples.
  283.  
  284. -------------------------- End of Note ----------------------------
  285.  
  286.  
  287. Alternatively, you may type ^D (control-D), i.e., press the key D while
  288. pressing down the CNTL key.
  289.  
  290.         >^DBye.
  291.         %
  292.  
  293.      The top-level loop of KCL is almost the same as that defined in
  294. Section 20.2 of the Common Lisp Reference Manual.  Since the input from the
  295. terminal is in line mode, each top-level form should be followed by a
  296. newline.  If more than one value is returned by the evaluation of the
  297. top-level form, the values will be printed successively.  If no value is
  298. returned, then nothing will be printed.
  299.  
  300.         >(values 1 2)
  301.         1
  302.         2
  303.  
  304.         >(values)
  305.         
  306.         >
  307.  
  308.  
  309.      When an error is signalled, control will enter the break loop.
  310.  
  311.         >(defun foo (x) (bar x))
  312.         foo
  313.  
  314.         >(defun bar (y) (bee y y))
  315.         bar
  316.  
  317.         >(foo 'lish)
  318.         Error: The function BEE is undefined.
  319.         Error signalled by BAR.
  320.  
  321.         Broken at BAR.
  322.         >>
  323.  
  324. '>>' in the last line is the prompt of the break loop.  Like in the
  325. top-level loop, the prompt will be prefixed by the current package name, if
  326. the current package is other than the user package.
  327.  
  328.      To go back to the top-level loop, type :q.
  329.  
  330.         >>:q
  331.  
  332.         Top level.
  333.         >
  334.  
  335. See Section 5.4 for the details of the break loop.
  336.  
  337.      In KCL on Unix, the terminal interrupt (usually caused by typing ^C
  338. (control-C) or by typing DELETE) is a kind of error.  It breaks the running
  339. program and calls the break level loop.
  340.  
  341.      Example:
  342.  
  343.         >(defun foo () (do () (nil)))
  344.         foo
  345.  
  346.         >(foo)
  347.         ^C
  348.         Correctable error: Console interrupt.
  349.         Signalled by DO.
  350.  
  351.         Broken at FOO.
  352.         >>
  353.  
  354.  
  355. ---------------------- Note to KCL/AOS users----------------------
  356.  
  357. In KCL/AOS, the console interrupt caused by typing ^C (control-C) followed
  358. by ^A (control-A) is a kind of error.  Typing ^C and ^A breaks the running
  359. program and calls the break loop.  On the other hand, the console interrupt
  360. caused by ^C and ^B (control-B) will immediately terminate KCL. 
  361.  
  362.      Example:
  363.         >(defun foo () (do () (nil)))
  364.         foo
  365.  
  366.         >(foo)
  367.         ^C^A
  368.         Correctable error: Console interrupt.
  369.         Signalled by DO.
  370.  
  371.         Broken at FOO.
  372.         >>(foo)
  373.         ^C^B
  374.         *ABORT*
  375.         CONSOLE INTERRUPT
  376.         ERROR: FROM PROGRAM
  377.         LEVEL 1
  378.         x,kcl
  379.         )
  380.  
  381. ---------------------------End of Note----------------------------
  382.  
  383.  
  384.  
  385.  
  386.  
  387.                      Chapter 2. Data Types
  388.  
  389.  
  390. KCL supports all Common Lisp data types exactly as defined in the
  391. Common Lisp Reference Manual.  This chapter simply complements
  392. Chapter 2 of the Common Lisp Reference Manual, by
  393. describing implementation dependent features of Common Lisp data
  394. types.  Each section in this chapter corresponds to the section in Chapter 2
  395. of the Common Lisp Reference Manual, with the same section title.
  396.  
  397.  
  398. 2.1. Numbers
  399.  
  400. 2.1.1. Integers
  401.  
  402.      Fixnums in KCL are those integers
  403. in the range -(2 to the power of 31) to
  404. (2 to the power of 31)-1, inclusive.  Other integers are bignums.  
  405. Thus 25 factorial (25!)
  406.  
  407.     15511210043330985984000000
  408.  
  409. is certainly a bignum in KCL.
  410.  
  411.      Common Lisp constants related to integers have the following values
  412. in KCL.
  413.  
  414.     most-positive-fixnum = 2147483647 = (2 to the power of 31)-1
  415.     most-negative-fixnum = -2147483648 = -(2 to the power of 31)
  416.  
  417.     boole-1 = 3
  418.     boole-2 = 5
  419.     boole-and = 1
  420.     boole-andc1 = 4
  421.     boole-andc2 = 2
  422.     boole-c1 = 12
  423.     boole-c2 = 10
  424.     boole-clr = 0
  425.     boole-eqv = 9
  426.     boole-ior = 7
  427.     boole-nand = 14
  428.     boole-nor = 8
  429.     boole-orc1 = 13
  430.     boole-orc2 = 11
  431.     boole-set = 15
  432.     boole-xor = 6
  433.  
  434. See Chapter 12 of the Common Lisp Reference Manual for their
  435. meanings.
  436.  
  437.  
  438. 2.1.2. Ratios
  439.  
  440. There are no implementation-dependent features for ratios.
  441.  
  442.  
  443. 2.1.3. Floating-Point Numbers
  444.  
  445. KCL provides two distinct internal floating-point formats.  One format
  446. is short; the other is single and serves also as double and
  447. long.  The data types single-float, double-float, and long-float
  448. are considered to be identical, but short-float is distinct. 
  449. An expression such as (eql 1.0s0 1.0d0) is false, but
  450. (eql 1.0f0 1.0d0) is true.  Similarly,
  451. (typep 1.0L0 'short-float) is false, but
  452. (typep 1.0L0 'single-float) is true.  For output purposes all
  453. floating-point numbers are assumed to be of short
  454. or single format.
  455.  
  456.      The floating-point precisions are:
  457.  
  458.     Format      KCL/AOS         KCL/VAX KCL/SUN         KCL/UST
  459.     ----------------------------------------------------------------
  460.     Short       24 bits         23 bits         24 bits         24 bits
  461.     Single      56 bits         55 bits         53 bits         53 bits
  462.     Double      56 bits         55 bits         53 bits         53 bits
  463.     Long        56 bits         55 bits         53 bits         53 bits
  464.  
  465. The floating-point exponent sizes are:
  466.  
  467.     Format      KCL/AOS         KCL/VAX KCL/SUN         KCL/UST
  468.     ----------------------------------------------------------------
  469.     Short       7 bits          8 bits          8 bits          8 bits
  470.     Single      7 bits          8 bits          11 bits         11 bits
  471.     Double      7 bits          8 bits          11 bits         11 bits
  472.     Long        7 bits          8 bits          11 bits         11 bits
  473.  
  474. There is no "minus zero."  (eql 0.0 -0.0) is true.
  475.  
  476.      Common Lisp constants related to floating-point numbers have the
  477. following values in KCL.
  478.  
  479.     most-positive-short-float
  480.       = - most-negative-short-float
  481.       = 7.237005s75 (KCL/AOS)
  482.         1.701412s38 (KCL/VAX)
  483.         3.402823s38 (KCL/SUN and KCL/UST)
  484.  
  485.     least-positive-short-float
  486.       = - least-negative-short-float
  487.       = 5.397605s-79 (KCL/AOS)
  488.         2.938736s-39 (KCL/VAX)
  489.         1.401298s-45 (KCL/SUN and KCL/UST)
  490.  
  491.     most-positive-long-float
  492.       = most-positive-double-float
  493.       = most-positive-single-float
  494.       = - most-negative-long-float
  495.       = - most-negative-double-float
  496.       = - most-negative-single-float
  497.       = 7.237005577332264f75 (KCL/AOS)
  498.         1.701411834604692f38 (KCL/VAX)
  499.         1.797693134862315f308 (KCL/SUN and KCL/UST)
  500.  
  501.     least-positive-long-float
  502.       = least-positive-double-float
  503.       = least-positive-single-float
  504.       = - least-negative-long-float
  505.       = - least-negative-double-flo
  506.       = - least-negative-single-float
  507.       = 5.397605346934027f-79 (KCL/AOS)
  508.         2.938735877055719f-39 (KCL/VAX)
  509.         4.940656458412469f-324 (KCL/SUN and KCL/UST)
  510.  
  511.     short-float-epsilon
  512.       = 4.468372s-7 (KCL/AOS)
  513.         6.938894s-18 (KCL/VAX)
  514.         2.980232s-8 (KCL/SUN and KCL/UST)
  515.  
  516.     short-float-negative-epsilon
  517.       = 2.980232s-8 (KCL/AOS)
  518.         6.938894s-18 (KCL/VAX)
  519.         2.980232s-8 (KCL/SUN and KCL/UST)
  520.  
  521.     long-float-epsilon
  522.       = double-float-epsilon
  523.       = single-float-epsilon
  524.       = 1.110223024625157f-16 (KCL/AOS)
  525.         6.938893903907228f-18 (KCL/VAX)
  526.         5.5511151231257827f-17 (KCL/SUN and KCL/UST)
  527.  
  528.     long-float-negative-epsilon
  529.       = double-float-negative-epsilon
  530.       = single-float-negative-epsilon
  531.       = 6.938893903907228f-18 (KCL/AOS)
  532.         6.938893903907228f-18 (KCL/VAX)
  533.         5.5511151231257827f-17 (KCL/SUN and KCL/UST)
  534.  
  535.     pi = 3.141592653589793
  536.  
  537. See Chapter 12 of the Common Lisp Reference Manual for their meanings.
  538.  
  539.  
  540. 2.1.4. Complex Numbers
  541.  
  542. There are no implementation-dependent features for complex numbers.
  543.  
  544. 2.2. Characters
  545.  
  546. 2.2.1. Standard Characters
  547.  
  548. KCL supports all standard and semi-standard characters listed in Section
  549. 2.2.1 of the Common Lisp Reference Manual.  Non-printing characters have
  550. the following character codes.
  551.  
  552.     Character           Code (in octal)
  553.     --------------------------------
  554.     #\Space             040
  555.     #\Newline           012
  556.     #\Backspace 010
  557.     #\Tab               011
  558.     #\Linefeed          012
  559.     #\Page              014
  560.     #\Return            015
  561.     #\Rubout            177
  562.  
  563. Note that #\Linefeed is synonymous with #\Newline and
  564. thus is a member of standard-char.  Other semi-standard characters
  565. are not members of standard-char.
  566.  
  567.  
  568. ---------------------- Note to KCL/AOS users----------------------
  569.  
  570. KCL/AOS uses 025 (in octal) as the character code of #\Backspace.
  571.  
  572. ---------------------------End of Note----------------------------
  573.  
  574.  
  575.  
  576. 2.2.2. Line Divisions
  577.  
  578. Since KCL represents the #\Newline character by a single code 12, problems
  579. with line divisions discussed in Section 2.2.2 of the Common Lisp Reference
  580. Manual cause no problem in KCL.
  581.  
  582.  
  583. 2.2.3. Non-standard Characters
  584.  
  585. KCL supports no additional non-standard characters.
  586.  
  587. 2.2.4. Character Attributes
  588.  
  589. The bit and font fields of KCL characters are always 0.
  590.  
  591.      Common Lisp constants related to characters
  592. have the following values in KCL.
  593.  
  594.     char-bits-limit = 1 
  595.     char-code-limit = 256 
  596.     char-control-bit = 0 
  597.     char-font-limit = 1 
  598.     char-hyper-bit = 0 
  599.     char-meta-bit = 0 
  600.     char-super-bit = 0 
  601.  
  602. See Chapter 13 of the Common Lisp Reference Manual for their meanings.
  603.  
  604.  
  605. 2.2.5. String Characters
  606.  
  607. Since the bit and font fields of KCL characters are always 0, string-char
  608. is considered to be identical to character.
  609.  
  610.  
  611. 2.3. Symbols
  612.  
  613. The print name of a symbol may consist of up to 16777216 (i.e., the value
  614. of array-total-size-limit) characters.  However, when a symbol is read, the
  615. number of characters (not counting escape characters) in the print name is
  616. limited to 2048.
  617.  
  618.  
  619. 2.4. Lists and Conses
  620.  
  621. There are no implementation-dependent features for lists and conses.
  622.  
  623.  
  624. 2.5. Arrays
  625.  
  626.      KCL arrays can have up to 64 ranks.
  627.  
  628.      When the value of the Common Lisp variable *print-array* (see Section
  629. 22.1.6 of the Common Lisp Reference Manual) is nil, then bit-vectors are
  630. printed as #<a bit-vector>, other vectors are printed as #<a vector>, and
  631. other arrays are printed as #<an array>.
  632.  
  633.      Common Lisp constants related to arrays have the following values in
  634. KCL.
  635.  
  636.     array-dimension-limit = 16777216
  637.     array-rank-limit = 64 
  638.     array-total-size-limit = 16777216 
  639.  
  640. See Section 17.1 of the Common Lisp Reference Manual for their meanings.
  641.  
  642.  
  643. 2.5.1. Vectors
  644.  
  645. In KCL, array elements are represented in one of six ways depending on the
  646. type of the array.
  647.  
  648. Array Type                                      Element Representation
  649.  
  650. ---------------------------------------------------------------
  651.  (array t) and (vector t)                       a cell pointer
  652.  (array fixnum) and (vector fixnum)             32 bit signed 
  653.                                                 integer
  654.  (array string-char) and string                 8 bit code
  655.  (array short-float) and (vector short-float)   32 bit
  656.                                                 floating point
  657.  (array long-float) and (vector long-float)     64 bit floating point
  658.  (array bit) and bit-vector                     1 bit bit
  659.  
  660.  
  661. 2.5.2. Strings
  662.  
  663. A string may consists of up to 16777216 (i.e., the value of
  664. array-total-size-limit) characters.  However, when a string is read, the
  665. number of characters (not counting escape characters) in the string is
  666. limited to 2048.
  667.  
  668.  
  669. 2.5.3. Bit-Vectors
  670.  
  671. There are no implementation-dependent features for bit-vectors.
  672.  
  673.  
  674. 2.6. Hash Tables
  675.  
  676. All hash tables are printed as #<a hash-table>.
  677.  
  678.  
  679. 2.7. Readtables
  680.  
  681. All readtables are printed as #<a readtable>.
  682.  
  683.  
  684. 2.8. Packages
  685.  
  686.      The following packages are built into KCL.
  687.  
  688.     lisp  user  keyword  system  compiler
  689.  
  690. The compiler package contains symbols used by the KCL compiler.  Other
  691. packages are described in Section 11.6 of the Common Lisp Reference Manual.
  692. The system package has two nicknames sys and si; system:symbol may be
  693. written as sys:symbol or si:symbol.  Other packages have no nicknames.
  694.  
  695.      Packages are printed as #<package-name package>.
  696.  
  697.  
  698. 2.9. Pathnames
  699.  
  700.      KCL provides a # macro #" that reads a pathname:  #"string" is
  701. equivalent to (pathname "string").  For example,
  702.  
  703.         #"foo.lsp"
  704.  
  705. is equivalent to
  706.  
  707.         (pathname "foo.lsp").
  708.  
  709. The same format is used when a pathname is printed.
  710.  
  711.      The initial value of the Common Lisp variable 
  712. *default-pathname-defaults* is #"" (or, equivalently, (pathname "")).
  713.  
  714.      A pathname in the file system of Common Lisp consists of the following
  715. six elements:
  716.  
  717.         host  device  directory  name  type  version
  718.  
  719. Among these elements, KCL does not use host, device, and version.  That is,
  720. when converting a namestring into a pathname, KCL turns these three
  721. elements into nil.  Conversely, when converting a pathname into a
  722. namestring, KCL ignores these three elements.
  723.  
  724.      In the sequel, we explain how KCL converts a namestring into
  725. a pathname.
  726.  
  727.      If a namestring contains one or more periods '.', the last 
  728. period separates the namestring into the file name and the filetype.
  729.  
  730.         "foo.lsp"
  731.                 name:           "foo"
  732.                 type:           "lsp"
  733.  
  734.         "a.b.c"
  735.                 name:           "a.b"
  736.                 type:           "c"
  737.  
  738. If a namestring ends with a period, the filetype becomes the null string.
  739.  
  740.         "foo."
  741.                 name:           "foo"
  742.                 type:           "" (null string)
  743.  
  744. If a namestring begins with a period, the file name becomes nil.
  745.  
  746.         ".lsp"
  747.                 name:           nil
  748.                 type:           "lsp"
  749.  
  750. If a namestring contains no period, the filetype is nil.
  751.  
  752.         "foo"
  753.                 name:           "foo"
  754.                 type:           nil
  755.  
  756. In a pathname, the file directory is represented as a list.
  757.  
  758.         "common/demo/foo.lsp"
  759.                 directory:      ("common" "demo")
  760.                 name:           "foo"
  761.                 type:           "lsp"
  762.  
  763. If a namestring does not contain a directory, the directory component of
  764. the pathname is nil.
  765.  
  766.         "foo.lsp"
  767.                 directory:      nil
  768.                 name:           "foo"
  769.                 type:           "lsp"
  770.  
  771. In a pathname, the root directory is represented by the keyword :root.
  772.  
  773.         "/usr/common/foo.lsp"
  774.                 directory:       (:root "usr" "common")
  775.                 name:           "foo"
  776.                 type:           "lsp"
  777.  
  778. The abbreviation symbols '.' and '..' may be used in a namestring.
  779.  
  780.         "./demo/queen.lsp"
  781.                 directory:      (:current  "demo")
  782.                 name:           "queen"
  783.                 type:           "lsp"
  784.  
  785.         "../../demo/queen.lsp"
  786.                 directory:      (:parent :parent "demo")
  787.                 name:           "queen"
  788.                 type:           "lsp"
  789.  
  790. :current and :parent represent the current directory and the parent
  791. directory, respectively.
  792.  
  793.     The part of a namestring after the last slash '/' is always regarded as
  794. representing the file name and the filetype.  In order to represent a
  795. pathname with both the name and the filetype nil, end the pathname with a
  796. slash.
  797.  
  798.         "/usr/common/"
  799.                 directory:      (:root "usr" "common")
  800.                 name:           nil
  801.                 type:           nil
  802.  
  803.         "/usr/common/.lsp"
  804.                 directory:      (:root "usr" "common")
  805.                 name:           nil
  806.                 type:           "lsp"
  807.  
  808. '*' in the place of file name or filetype becomes :wild.
  809.  
  810.         "*.lsp"
  811.                 name:           :wild
  812.                 type:           "lsp"
  813.  
  814.         "foo.*"
  815.                 name:           "foo"
  816.                 type:           :wild
  817.  
  818.  
  819. ----------------------Note to KCL/AOS users----------------------
  820.  
  821. In KCL/AOS, all the lower-case letters are turned into upper-case letters
  822. by pathname conversions.  Thus, for example,
  823.  
  824.         "foo.lsp"
  825.                 name:           "FOO"
  826.                 type:           "LSP"
  827.  
  828. KCL/AOS follows the convention of the AOS/VS file system:  The symbols
  829. '/',  '.',  '..', and '*'  in the examples above should be replaced by
  830. ':',  '=',  '^', and '-', respectively, in KCL/AOS.
  831.  
  832. ---------------------------End of Note----------------------------
  833.  
  834.  
  835.  
  836. 2.10. Streams
  837.  
  838. Streams are printed in the following formats.
  839.  
  840.  #<input stream file-name>
  841.      An input stream from the file file-name.
  842.  
  843.  #<output stream file-name>
  844.      An output stream to the file file-name.
  845.  
  846.  #<string-input stream from string>
  847.      An input stream generated by (make-string-input-stream 
  848. string).
  849.  
  850.  
  851.  #<a string-output stream>
  852.      An output stream generated by the function
  853.  make-string-output-stream
  854.  
  855.  #<a two-way stream>
  856.      A stream generated by the function make-two-way-stream.
  857.  
  858.  #<an echo stream>
  859.      A bidirectional stream generated by the function
  860.  make-echo-stream.
  861.  
  862.  #<synonym stream to symbol>
  863.      The stream generated by (make-synonym-stream symbol)
  864.  
  865.  #<a concatenated stream>
  866.      An input stream generated by the function make-concatenated-stream.
  867.  
  868.  #<a broadcast stream>
  869.      An output stream generated by the function
  870.  make-broadcast-stream.
  871.  
  872.  
  873. 2.11. Random-States
  874.  
  875. KCL provides a # macro '#$' that reads a random state.  #$integer is
  876. equivalent to (make-random-state integer).  The same format is used when a
  877. random state is printed.
  878.  
  879.  
  880. 2.12. Structures
  881.  
  882. There are no implementation-dependent features for structures.
  883.  
  884.  
  885. 2.13. Functions
  886.  
  887. An interpreted function (including macro expansion functions) is
  888. represented in one of the following formats.
  889.  
  890. (lambda lambda-list . body)
  891.  
  892.      A lambda-expression with null lexical environment and with no implicit
  893. block around it.  This type of function typically appears when '(lambda
  894. lambda-list . body) is evaluated.
  895.  
  896.  
  897. (lambda-block block-name lambda-list . body)
  898.  
  899.      A lambda-expression with null lexical environment but with an implicit
  900. block around it.  This type of function typically appears when (defun
  901. function-name lambda-list . body) is evaluated.  In this case, block-name
  902. is identical to function-name.
  903.  
  904.  
  905. (lambda-closure env1 env2 env3 lambda-list . body)
  906.  
  907.      A lambda-expression with lexical environments but with no implicit
  908. block around it.  This type of function typically appears when #'(lambda
  909. lambda-list) . body) (or, equivalently, (function (lambda lambda-list .
  910. body)) ) is evaluated.  env1, env2, and env3 represent the variable
  911. bindings, the local function/macro definitions, and the tag/block-name
  912. establishments, respectively, at the time the closure was created.
  913.  
  914.  
  915. (lambda-block-closure env1 env2 env3 block-name lambda-list . body)
  916.  
  917.      A lambda-expression with lexical environments and with an implicit
  918. block around it.  Local functions and local macros are represented in this
  919. format.  env1, env2, and env3 represent the variable bindings, the local
  920. function/macro bindings, and the tag/block-name establishments,
  921. respectively, at the time the local function/macro was created by flet,
  922. labels, or macrolet.  The block-name is identical to the local
  923. function/macro name.
  924.  
  925.      Compiled functions (including compiled macro-expansion
  926. functions) are printed in the following formats.
  927.  
  928.     #<compiled-function name>
  929.  or
  930.     #<compiled-closure nil>
  931.  
  932. Incidentally, the value of
  933.  (symbol-function special-form-name) is a list,
  934.  
  935.     (special . address)
  936.  
  937. if special-form-name names a special form.
  938.  
  939.      Common Lisp constants related to functions have the following values
  940. in KCL.
  941.  
  942.     call-arguments-limit = 64 
  943.     lambda-list-keywords = (&optional &rest &key &allow-other-keys &aux
  944.                             &whole &environment &body)
  945.                             
  946.     lambda-parameters-limit = 64 
  947.     multiple-values-limit = 32 
  948.  
  949. Refer to the Common Lisp Reference Manual for their meanings.
  950.  
  951.  
  952. 2.14. Unreadable Data Objects
  953.  
  954. There are no implementation-dependent features for unreadable data objects.
  955.  
  956. 2.15. Overlap, Inclusion, and Disjointness of Types
  957.  
  958. In KCL, the types number and array are certainly subtypes of common, since
  959. KCL does not extend the set of objects of these types.
  960.  
  961.  
  962.  
  963.  
  964.                     Chapter 3. Input and Output
  965.  
  966.  
  967.  
  968. 3.1. Read Macros
  969.  
  970.      The following # macros are introduced in KCL.
  971.  
  972.         #"      #"string" reads a pathname.
  973.                 #"string" is equivalent to
  974.                 (pathname "string").
  975.  
  976.         #$      #$integer reads a random state.
  977.                 #$integer is equivalent to
  978.                 (make-random-state integer).
  979.  
  980.      The # macro '#,' works as described in the Common Lisp Reference
  981. Manual, only if it is included in a constant object.  The forms immediately
  982. after '#,' below will be evaluated when the compiled code is loaded.
  983.  
  984.         '#,x
  985.         '(a b c (d #,e f) g)
  986.         #(1 2 3 #,(+ a b c) 5 6)
  987.         #C(0.0 #,(exp 1))
  988.  
  989. Otherwise, the effect of using '#,' is unpredictable.  Note that, when
  990. interpreted code is loaded, '#,' has the same effect as the # macro '#.'.
  991.  
  992.  
  993. 3.2. Input and Output Functions
  994.  
  995. The input and output functions of KCL almost follow the definitions in
  996. Chapter 22 of the Common Lisp Reference Manual.  Most of the differences
  997. come from the fact that, in KCL, input from the terminal is always in line
  998. mode and binary I/O is not supported.
  999.  
  1000.      In KCL, *terminal-io* is a two-way stream from the standard input and
  1001. to the standard output.  The echoing to the terminal is performed by the
  1002. underlying operating system.  In particular, when a disk file is assigned
  1003. to the standard output, nothing will be echoed at the terminal.
  1004.  
  1005.      Those functions that deviate from the definitions in the Common Lisp
  1006. Reference Manual are listed below.
  1007.  
  1008.  
  1009. load pathname &key :print :verbose :if-does-not-exist [Function] 
  1010.  
  1011. If pathname does not specify the filetype of the input file, then load
  1012. first tries to load a file with the filetype .o, i.e., the fasl file (see
  1013. Chapter 6).  If it fails, then load tries to load a file with the filetype
  1014. .lsp.  KCL assumes that .lsp is the standard filetype for source files.  If
  1015. it fails again, then load will load the specified file with no filetype.
  1016.  
  1017. load recognizes a file as a fasl file if and only if the filetype of the
  1018. file is .o.  Other files are assumed to be source files.
  1019.  
  1020.  
  1021. ----------------------Note to KCL/AOS users----------------------
  1022.  
  1023. In KCL/AOS, the filetype of fasl files is .fasl (see Chapter 6).
  1024. Therefore, if the pathname argument does not explicitly specify the
  1025. filetype, load first tries to load a file with the filetype
  1026. .fasl.  In addition, load recognizes a file as a fasl file if and
  1027. only if the filetype of the file is .fasl.
  1028.  
  1029. ---------------------------End of Note----------------------------
  1030.  
  1031.  
  1032.  
  1033. open                                                        [Function]
  1034.  
  1035.   The argument to the keyword variable :element-type is ignored and
  1036.   :element-type is always bound to the value string-char.
  1037.  
  1038.  
  1039. close                                                        [Function]
  1040.  
  1041.   The keyword variable :abort is always ignored.
  1042.  
  1043.  
  1044. listen                                                       [Function]
  1045.  
  1046.   listen always returns t.
  1047.  
  1048.  
  1049. read-char-no-hang                                            [Function]
  1050.  
  1051.   read-char-no-hang is equivalent to read-char.
  1052.  
  1053.  
  1054. clear-input                                                  [Function]
  1055.  
  1056. clear-output                                                 [Function]
  1057.  
  1058.   clear-input and clear-output simply return nil without doing anything.
  1059.  
  1060.  
  1061. read-byte                                                    [Function]
  1062.  
  1063. write-byte                                                   [Function]
  1064.  
  1065.   These functions may operate on any stream.  They read or write a byte (8
  1066.   bits) at a time.
  1067.  
  1068.  
  1069. princ                                                        [Function]
  1070. write-char                                                   [Function]
  1071. write-byte                                                   [Function]
  1072.  
  1073.   These functions do not always flush the stream.  The stream is flushed when
  1074.  
  1075.   1. a newline character is written, or
  1076.  
  1077.   2. the input from the terminal is requested in the case that these
  1078.   functions operate on *terminal-io*.
  1079.  
  1080.  
  1081.  
  1082.  
  1083.  
  1084.                        Chapter 4. Memory Management
  1085.  
  1086.  
  1087.  
  1088. 4.1. Implementation Types
  1089.  
  1090. Each KCL object belongs to one of the 22 implementation types.  The
  1091. implementation types are shown in Table 4-1 with the corresponding Common
  1092. Lisp data types.  In the table, the compiled functions are divided into two
  1093. implementation types; cfun is the type of compiled functions without
  1094. environment, and cclosure is the type of compiled functions with
  1095. environment (i.e., the type of compiled closures).  spice is the type of
  1096. internal data used by KCL, and does not correspond to any Common Lisp data
  1097. type.
  1098.  
  1099.                 Table 4-1  Implementation Types
  1100.  
  1101.         Implementation Type     Common Lisp Data Type
  1102.         ----------------------------------------------------------------
  1103.         cons                    cons
  1104.         fixnum                  fixnum
  1105.         bignum                  bignum
  1106.         ratio                   ratio
  1107.         short-float             short-float
  1108.         long-float              long-float (= double-float = single-float)
  1109.         complex                 complex
  1110.         character               character
  1111.         symbol                  symbol
  1112.         package                 package
  1113.         hash-table              hash-table
  1114.         array                   (and array (not vector))
  1115.         vector                  (and vector (not string) (not bit-vector))
  1116.         string                  string
  1117.         bit-vector              bit-vector
  1118.         structure               structure
  1119.         stream                  stream
  1120.         random-state            random-state
  1121.         readtable               readtable
  1122.         cfun                    compiled-function without environment
  1123.         cclosure                compiled-function with environment
  1124.         spice                   none
  1125.  
  1126.  
  1127.      Each object is represented by a cell allocated in the heap area of the
  1128. interpreter.  The size of the cell is determined by the implementation type
  1129. of the object.
  1130.  
  1131.      The implementation types are classified according to the size of the
  1132. cells for the objects of the type, as shown in Table 4-2.  The size of the
  1133. cells in the same type class is the same.
  1134.  
  1135.                 Table 4-2  Classification of Implementation Types
  1136.  
  1137.         Class   Implementation Types    
  1138. ----------------------------------------------------------------
  1139.             1   cons bignum ratio long-float complex
  1140.             2   fixnum short-float character random-state readtable 
  1141.                  spice
  1142.             3   symbol package
  1143.             4   array hash-table vector bit-vector stream pathname 
  1144.                  cclosure
  1145.             5   string cfun
  1146.             6   structure
  1147.  
  1148.  
  1149.      For objects of the (implementation) types readtable, symbol, package,
  1150. array, hash-table, vector, bit-vector, stream, cclosure, string, cfun, and
  1151. structure, the cell is simply a header of the object.  The body of the
  1152. object is allocated separately from the cell and is managed in a different
  1153. manner.  The memory space occupied by the body of such an object is called
  1154. a block.  A block is either contiguous or relocatable depending on the area
  1155. in which it is allocated.  The difference between the two areas will be
  1156. explained below.  Table 4-3 lists these types, along with the contents of
  1157. the body and the kind of the block.
  1158.  
  1159.                 Table 4-3  Types with Bodies
  1160.  
  1161.         Type            Body                    Block
  1162.         -----------------------------------------------------------
  1163.         readtable       read table              contiguous
  1164.         symbol          symbol name             relocatable
  1165.         package         hash table              contiguous
  1166.         array           array body              relocatable or 
  1167.                                                               contiguous
  1168.         hash-table      hash table              relocatable
  1169.         vector          vector body             relocatable or
  1170.                                                                contiguous
  1171.         bit-vector      bit-vector body         relocatable or 
  1172.                                                                 contiguous
  1173.         stream          I/O buffer              contiguous
  1174.         cclosure        code                    contiguous
  1175.         string          string body             relocatable or
  1176.                                                               contiguous
  1177.         cfun            code                    contiguous
  1178.         structure       structure body          relocatable
  1179.  
  1180.  
  1181.      Usually, the body of an array, a vector, a bit-vector, or a string is
  1182. allocated as a relocatable block.  In KCL, the function make-array takes an
  1183. extra keyword argument :static.  If the :static argument is supplied with a
  1184. non-nil value, then the body of the array is allocated as a contiguous
  1185. block.
  1186.  
  1187.  
  1188. 4.2. Heap and Relocatable Areas
  1189.  
  1190.     The memory space of KCL is divided into two parts:  the heap area and
  1191. the relocatable area.  Both areas occupy a contiguous space in the memory.
  1192.  
  1193.      Cells of KCL objects are allocated in the heap.  KCL divides the heap
  1194. into pages (1 page = 2048 bytes), and each page consists of cells in the
  1195. same type class (see Table 4-2).  Cells in different type classes are
  1196. allocated in different pages.  Some blocks are also allocated in the heap:
  1197. They are called contiguous blocks.  The pages for contiguous blocks contain
  1198. only contiguous blocks.  Thus each page in the heap is either a page for
  1199. cells in a particular type class, or a page for contiguous blocks.  Blocks
  1200. not in the heap are called relocatable blocks and are allocated in the
  1201. relocatable area.
  1202.  
  1203.      The user may specify the maximum number of pages that can be allocated
  1204. for each type class by calling the KCL specific function allocate.  There
  1205. is also a limit on the number of pages for contiguous blocks; the limit can
  1206. be altered by calling the KCL specific function allocate-contiguous-pages.
  1207. The size of the relocatable area is specified by the KCL specific function
  1208. allocate-relocatable-pages.  See Section 4.4 for these functions.
  1209.  
  1210.      In some installations of KCL, the total amount of memory that KCL can
  1211. use is limited.  In such cases, the entire memory may become exhausted
  1212. before the maximum number of pages for each type class, for contiguous
  1213. blocks, or for the relocatable area have been allocated.
  1214.  
  1215.      The heap lies in a part of memory with lower address than the
  1216. relocatable area and there is a "hole" between the two areas (see Figure
  1217. 4-1).  On request for a new page of heap, the page with the lowest address
  1218. in the hole is used.  When the hole is exhausted, the relocatable area is
  1219. shifted toward the higher address space and a new hole of an appropriate
  1220. size is created between the two areas.
  1221.  
  1222.                 Figure 1  Heap and Relocatable Area
  1223.  
  1224.      lower address                                  higher address
  1225.         ---------------------- - - - 2-------------------
  1226.         |        heap        | hole  | relocatable area |
  1227.         7--------------------- - - - 8------------------9
  1228.  
  1229.  
  1230.  
  1231. 4.3. The Garbage Collector
  1232.  
  1233. The garbage collector of KCL has three levels according to what it
  1234. collects:
  1235.  
  1236.         1. cells
  1237.         2. cells and relocatable blocks
  1238.         3. cells, relocatable blocks and contiguous blocks.
  1239.  
  1240. In levels 2 and 3, the relocatable area is shifted to the higher address
  1241. space to reserve an appropriate number of pages in the hole.
  1242.  
  1243.      For each type class, KCL keeps a free list of unused cells, and when
  1244. the free list is exhausted, a new page is allocated, or the garbage
  1245. collector is invoked, depending on whether the maximum number of pages for
  1246. that class have been allocated or not.
  1247.  
  1248.      The garbage collector does not compactify the heap.  That is, cells
  1249. and contiguous blocks are never moved to another place.  Moreover, once a
  1250. page is allocated for a particular type class or for contiguous blocks,
  1251. that page will never be freed for other classes, even if the entire page
  1252. becomes garbage.
  1253.  
  1254.      On the other hand, the relocatable area is compactified during level 2
  1255. and level 3 of garbage collection.  A relocatable block is really
  1256. relocatable.
  1257.  
  1258.      The garbage collector is automatically invoked in one of the following
  1259. situations.  The number in the parentheses indicates the level of garbage
  1260. collection that is performed.
  1261.  
  1262.         * The free list of a certain type class is exhausted
  1263. after the maximum number of pages have been allocated for that
  1264. type class (1).
  1265.  
  1266.         * The hole is exhausted (2).
  1267.  
  1268.         * The relocatable area is exhausted after the maximum number of
  1269. pages have been allocated for the relocatable area (2).
  1270.  
  1271.         * The contiguous blocks are exhausted after the maximum number of
  1272. pages have been allocated for contiguous blocks (3).
  1273.  
  1274.      The garbage collector is also invoked by the following KCL specific
  1275. function.
  1276.  
  1277. gbc x                                               [Function]
  1278.  
  1279. The garbage collector is invoked with the level specified by x.  If x is
  1280. nil, the garbage collector is invoked for level 1 garbage collection.  If x
  1281. is t, it is invoked for level 3 garbage collection.  Otherwise, it is
  1282. invoked for level 2 garbage collection.
  1283.  
  1284. 4.4. Allocation Functions
  1285.  
  1286. The following functions are used to set or inspect the (maximum) number of
  1287. pages for each type class, for contiguous blocks, or for relocatable
  1288. blocks.
  1289.  
  1290. allocate type number                                    [Function]
  1291.  
  1292.   Sets the maximum number of pages for the type class of the implementation
  1293.   type type to number.  If more than number pages have already been
  1294.   allocated, an error is signalled.
  1295.  
  1296.  
  1297. allocated-pages type                                    [Function]
  1298.  
  1299.   Returns the number of pages currently allocated for the type class of the
  1300.   implementation type type.
  1301.  
  1302.  
  1303. maximum-allocatable-pages type                          [Function]
  1304.  
  1305.   Returns the current maximum number of pages for type class of the
  1306.   implementation type type .
  1307.  
  1308.  
  1309. allocate-contiguous-pages number                         [Function]
  1310.  
  1311.   Sets the maximum number of pages for contiguous blocks to number.
  1312.  
  1313.  
  1314. allocated-contiguous-pages                               [Function]
  1315.  
  1316.   Returns the number of pages allocated for contiguous blocks.
  1317.  
  1318.   
  1319. maximum-contiguous-pages                                 [Function]
  1320.  
  1321.   Returns the current maximum number of pages for contiguous blocks.
  1322.  
  1323.  
  1324. allocate-relocatable-pages number                        [Function]
  1325.  
  1326.   Sets the maximum number of pages for relocatable blocks to number.  The
  1327.   relocatable area is expanded to number pages immediately.  Therefore, "the
  1328.   current maximum number" and "the number of pages allocated" have the same
  1329.   meanings for relocatable blocks.
  1330.  
  1331.  
  1332. allocated-relocatable-pages                              [Function]
  1333.  
  1334.   Returns the number of pages allocated for relocatable blocks.
  1335.  
  1336.  
  1337.      If the pages for a particular type class are exhausted after the
  1338. maximum number of pages for that class have been allocated, and if there
  1339. remain no free cells (actually, if there remain very few cells), KCL
  1340. behaves as directed by the value of the KCL specific variable
  1341. *ignore-maximum-pages*.  If the value is nil, then KCL signals a
  1342. correctable error and enters the break loop.  The user can reset the
  1343. maximum number by calling allocate and then continue the execution of the
  1344. program by typing :r.
  1345.  
  1346.      Example:
  1347.  
  1348.         >(make-list 100000)
  1349.  
  1350.         Correctable error: The storage for CONS is exhausted.
  1351.                            Currently, 531 pages are allocated.
  1352.                            Use ALLOCATE to expand the space.
  1353.         Signalled by MAKE-LIST.
  1354.  
  1355.         Broken at FUNCALL.
  1356.         >>(ALLOCATE 'CONS 1000)
  1357.         t
  1358.  
  1359.         >>:r
  1360.  
  1361.         (nil nil nil nil nil nil nil nil nil nil ............
  1362.  
  1363. The user can also reset the maximum number of pages for relocatable blocks
  1364. and for contiguous blocks in a similar manner.  On the other hand, if the
  1365. value of *ignore-maximum-pages* is non-nil, then KCL automatically
  1366. increments the maximum number of pages for the class by 50 percent.  The
  1367. initial value of *ignore-maximum-pages* is t.
  1368.  
  1369.  
  1370. 4.5. Storage Information
  1371.  
  1372. room &optional x                                        [Function]
  1373.  
  1374.   The function room prints the storage information.  The argument x is simply
  1375.   ignored and the output of room is always in the same format.  room prints
  1376.   the following information:
  1377.  
  1378.         * for each type class
  1379.                 * the number of pages so-far allocated for the type class
  1380.                 * the maximum number of pages for the type class
  1381.                 * the percentage of used cells to cells so-far 
  1382.                   allocated
  1383.                 * the number of times the garbage collector has been 
  1384.                   called to collect cells of the type class
  1385.                 * the implementation types that belong to the type class
  1386.         * the number of pages actually allocated for contiguous blocks
  1387.         * the maximum number of pages for contiguous blocks
  1388.         * the number of times the garbage collector has been called to 
  1389.           collect contiguous blocks
  1390.         * the number of pages in the hole
  1391.         * the maximum number of pages for relocatable blocks
  1392.         * the number of times the garbage collector has been called 
  1393.           to collect relocatable blocks
  1394.         * the total number of pages allocated for cells
  1395.         * the total number of pages allocated
  1396.         * the number of available pages
  1397.         * the number of pages KCL can use.
  1398.  
  1399. The number of times the garbage collector has been called is not shown, if
  1400. the number is zero.
  1401.  
  1402.      In the following example, the maximum of 531 pages have already been
  1403. allocated for the type class to which cons belongs, but only 16.9 percent
  1404. of the cells are actually used.  The garbage collector was once invoked to
  1405. collect cells in this type class.
  1406.  
  1407.  >(room)
  1408.   531/531   16.9%  1  cons bignum ratio long-float complex
  1409.     3/52    10.4%     fixnum short-float character random-state
  1410.                       readtable spice
  1411.    47/65    73.6%     symbol package
  1412.     3/71    32.4%     array hash-table vector bit-vector stream
  1413.                       pathname cclosure
  1414.    46/96    98.8%     string cfun
  1415.     1/32     2.3%     structure
  1416.  
  1417.    17/512             contiguous (3 blocks)
  1418.       14              hole
  1419.       50    47.4%  2  relocatable
  1420.  
  1421.    631 pages for cells
  1422.    712 total pages
  1423.  14840 pages available
  1424.  16384 maximum pages
  1425.  
  1426.  >
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433.                        Chapter 5. Debugging Facilities
  1434.  
  1435.  
  1436.  
  1437. 5.1. The Tracer
  1438.  
  1439. The Tracer causes selected functions to be traced.  When such a traced
  1440. function is invoked, it prints
  1441.  
  1442.         level > (name arg1...argn)
  1443.  
  1444. On return from a traced function, it prints
  1445.  
  1446.         < level (name value1... valuen)
  1447.  
  1448. name is the name of the traced function, args are the arguments, and values
  1449. are the return values.  level is a number which is incremented each time a
  1450. traced function is invoked and is decremented at the completion of the
  1451. invocation.  Trace print-outs are indented according to the level.
  1452.  
  1453.      In the current version of KCL, macros and special forms cannot be traced.
  1454.  
  1455.  
  1456. trace {function-name}*                               [Macro]
  1457.  
  1458. Causes one or more functions to be traced.  function-names must be symbols
  1459. and they are not evaluated.  If a function is called from a compiled
  1460. function, the call may not produce trace print-outs.  If this is the case,
  1461. the simplest way to get trace print-outs is to recompile the caller with a
  1462. notinline declaration for the called function (see Chapter 7).  trace
  1463. returns a name list of those functions that were traced by the call to
  1464. trace.  If no function-name is given, trace simply returnsa name list of
  1465. all the currently traced functions.
  1466.  
  1467.  
  1468. untrace {function-name}*                              [Macro]
  1469.  
  1470. Causes the specified functions to be not traced any more.  function-names
  1471. must be symbols and they are not evaluated.  untrace returns a name list of
  1472. those functions that were untraced by the call to untrace.  If no
  1473. function-name is given, untrace will untraceall the currently traced
  1474. functions and will return a list of their names.
  1475.  
  1476.  
  1477. 5.2. The Stepper
  1478.  
  1479. step form                                              [Macro]
  1480.  
  1481. Starts evaluating the form in the single-step mode.  In this mode, before
  1482. any form is evaluated, the Stepper will print the form and prompt the user
  1483. for a Stepper command.  The Stepper binds the two variables *print-level*
  1484. and *print-length* both to 2, so that the current form may not occupy too
  1485. much space on the screen.  A Stepper command will be executed when the user
  1486. types the single character for the command followed by the required
  1487. arguments, if any, and presses the newline key.  If the user presses the
  1488. newline key without having typed any character, then the Stepper will
  1489. assume that the Stepper command n was abbreviated.
  1490.  
  1491. The Stepper commands are:
  1492.  
  1493. n       Next.  Evaluates the current form in the single-step
  1494.                             mode.
  1495.  
  1496. s       Skip.  Evaluates the current form in the ordinary mode.
  1497.                             The single-step mode will be resumed at completion
  1498.                             of the evaluation.
  1499.  
  1500. p       Print.  Pretty-prints the current form and
  1501.                              then prompts again.
  1502.  
  1503. f fn    Function.  Evaluates the current
  1504.               form in the ordinary mode until the specified
  1505.               function fn is invoked.  If the
  1506.               specified function
  1507.               is not invoked at all, then this command has
  1508.               the same effects as the q command
  1509.               below.
  1510.  
  1511. q       Quit.  Evaluates the current form and any
  1512.                             other forms in the ordinary mode.
  1513.  
  1514. e form  Eval.  Evaluates the specified
  1515.                                 form in the ordinary mode and prints the
  1516.                                 resulting values.  
  1517.                                 Then prompts again with the same current
  1518.                                 form.
  1519.  
  1520. ?       Help.  Lists the Stepper commands.
  1521.  
  1522.  
  1523. 5.3.  Errors
  1524.  
  1525. *break-enable*                                    [Variable]
  1526.  
  1527. This variable is used to determine whether to enter the break loop (see
  1528. Section 5.4) when an error occurs.  Even the function break checks this
  1529. variable.  Initially, this variable is set to t, and thus an error will
  1530. invoke the break loop.  If the value is nil, functions that cause fatal
  1531. errors, such as error, will just print an error message and control will
  1532. return to the top-level loop (or to the current break loop, if already in
  1533. the break loop).  Functions that cause correctable errors, such as cerror,
  1534. will print an error message and a "continue message", and control will
  1535. return to the next form.  In KCL, backtrace is not
  1536.  part of an error message, but a break loop command will print backtrace.
  1537. Therefore, if *break-enable* is nil, no backtrace appears on the screen.
  1538.  
  1539. When the break loop is entered, *break-enable*will be bound to nil.
  1540.  
  1541.  
  1542. 5.4.  The Break Loop
  1543.  
  1544. The break loop is a read-eval-print loop similar to the top-level loop.  In
  1545. addition to ordinary Lisp forms, the break loop accepts various commands
  1546. with which the user can inspect and modify the state of the program
  1547. execution.  Each break loop command is identified with a keyword (i.e., a
  1548. symbol in the keyword package).  A break loop command is executed when the
  1549. user inputs a list whose first element is the keyword that identifies the
  1550. command.  The rest of the list is the arguments to the command.  They are
  1551. evaluated before being passed to the command.  If the command needs no
  1552. arguments, then the user may input only the keyword.  It is an error if the
  1553. given keyword does not identify any command.  Any other input to the break
  1554. loop is regarded as an ordinary Lisp form; the form will be evaluated and
  1555. the resulting values will be printed on the terminal.
  1556.  
  1557.      There can be several instances of the break loop at the same time, and
  1558. each such instance is identified by a level number.  When the break loop is
  1559. entered during execution in the top-level loop, the break loop instance is
  1560. given the level number 1.  The break loop instance that is entered from the
  1561. level n break loop is given the level number n+1.  The prompt of the level
  1562. n break loop is n+1 consecutive >'s, occasionally prefixed with the name of
  1563. the current package.
  1564.  
  1565.      The break loop keeps track of the invocation sequence of functions
  1566. (including special forms and macro expansion functions), which led up to
  1567. the break loop from the previous break loop (or from the top-level loop, if
  1568. the current break loop is level 1).  The invocation sequence is maintained
  1569. in a pushdown stack of events.  An event consists of an event function and
  1570. an event environment.  An event function is:
  1571.  
  1572.         1. an interpreted (i.e., not compiled) function (global 
  1573.            function, local function, lambda-expression, or closure),
  1574.         2. a special form within an interpreted function,
  1575.         3. a macro expansion function called from an 
  1576.            interpreted function,
  1577.         4. a compiled function called from an interpreted function, or
  1578.         5. a compiled function called from another compiled
  1579.            function which was compiled while the safety optimize
  1580.            level is 3 or with a notinline declaration for the called
  1581.            function (see Chapter 7).
  1582.  
  1583.      An event is pushed on the event stack when execution of its event
  1584. function begins, and is poped away at the completion of the execution.  An
  1585. event environment is the 'environment' of the event function at the time
  1586. the next event is pushed.  Actually, an event environment is a pointer to
  1587. the main stack of KCL.  For each interpreted event function (i.e., event
  1588. function in classes 1, 2, and 3), the pointer points to the first entry of
  1589. the three contiguous main stack entries that hold the lexical environment
  1590. of the event function.  For each compiled event function (i.e., event
  1591. function in classes 4 and 5), the pointer is set to the first entry of the
  1592. main stack area that is used locally by the compiled code.  In most cases,
  1593. the first argument to the compiled function is saved in the first entry,
  1594. the second argument in the second entry, and so on.  The local variables of
  1595. the function are allocated in the entries following the arguments.
  1596. However, this is not always the case.  Refer to Section 7.3 for variable
  1597. allocations in compiled functions.
  1598.  
  1599.      By break level commands, the user can choose one of the events as the
  1600. current event.  If the current event function is an interpreted event
  1601. function, then the break loop evaluates Lisp forms in the lexical
  1602. environment retrieved from the event environment.  In particular, local
  1603. variables may be referenced by the variable names, local functions and
  1604. local macros may be invoked as usual, established blocks may be exited
  1605. from, and tags may be used as the destination of go.  If the current
  1606. function is a compiled function, Lisp forms are evaluated in the null
  1607. environment.
  1608.  
  1609.      Within the break loop, each event is represented by the event symbol.
  1610. The :backtrace command, for example, lists events in terms of their event
  1611. symbols.  If the event function is a named function (global or local) or a
  1612. macro expansion function, then the function or macro name is used as the
  1613. event symbol.  If the event function is a special form, then the name of
  1614. the special form is used.  If the event function is a lambda-expression (or
  1615. a closure), then the symbol lambda (or lambda-closure) is used.
  1616.  
  1617.      To suppress unnecessary information, the user can hide (or make
  1618. invisible) some of the events.  Invisible events do not appear in the
  1619. backtrace, for example.  Initially, only those events are invisible whose
  1620. event symbols belong to the system internal package system.  When the break
  1621. loop is entered, the last visible event becomes the current event.
  1622.  
  1623.      The break loop commands are described below.  Some of the commands
  1624. allow abbreviation in the keywords that identify them.  For example, the
  1625. user may abbreviate :current as :c.  The break loop commands return no
  1626. values at all.
  1627.  
  1628.  
  1629. :current                                   [Break Loop Command]
  1630.  
  1631. :c                             [Abbreviated Break Loop Command]
  1632.  
  1633.   Prints the event symbol of the current event.
  1634.  
  1635. :previous &optional n                     [Break Loop Command]
  1636.  
  1637. :p &optional                  [Abbreviated Break Loop Command]
  1638.  
  1639.   Makes the n-th previous visible event the new current event.  Invisible
  1640.   events are not counted.  If there are less than n previous events, then the
  1641.   first visible event in the invocation sequence becomes the new current
  1642.   event.  n must be a positive integer and the default is 1.
  1643.  
  1644. :next &optional  n                         [Break Loop Command]
  1645.  
  1646. :n &optional n                 [Abbreviated Break Loop Command]
  1647.  
  1648.   Makes the n-th next visible event the new current event.  If there are less
  1649.   than n next events, then the last visible event in the invocation sequence
  1650.   becomes the new current event.  n must be a positive integer and the
  1651.   default is 1.
  1652.  
  1653.  
  1654. :backtrace                                 [Break Loop Command]
  1655.  
  1656. :b                             [Abbreviated Break Loop Command]
  1657.  
  1658.   Prints the event symbols of all visible events in order.  The symbol of the
  1659.   current event is printedin upper-case letters and the event symbols of
  1660.   other events are in lower-case.
  1661.  
  1662.  
  1663. :help                                        [Break Loop Command]
  1664.  
  1665. :h                               [Abbreviated Break Loop Command]
  1666.  
  1667.   Lists the break loop commands.
  1668.  
  1669.  
  1670. :quit &optional n                            [Break Loop Command]
  1671.  
  1672. :q &optional n                   [Abbreviated Break Loop Command]
  1673.  
  1674.   Returns control to the level n break loop.  If n is 0 or if n is omitted,
  1675.   then control will return to the top-level loop.  n must be a non-negative
  1676.   integer smaller than the current break level.
  1677.  
  1678.  
  1679. :resume                                       [Break Loop Command]
  1680.  
  1681. :r                                [Abbreviated Break Loop Command]
  1682.  
  1683.   Returns control to the caller of the break loop.  If the break loop has
  1684.   been entered from cerror, cerror returns nil as its value and control will
  1685.   resume at that point.  Otherwise, this command returns control to the
  1686.   previous break loop (or to the top-level loop, if the current break level
  1687.   is 1).
  1688.  
  1689.  
  1690. :variables                                  [Break Loop Command]
  1691.  
  1692. :v                              [Abbreviated Break Loop Command]
  1693.  
  1694.   Prints the names of the bound variables in the current environment.  To see
  1695.   the value of a bound variable, just type the variable name.
  1696.  
  1697.  
  1698. :functions                                  [Break Loop Command]
  1699.  
  1700.   Prints the names of the local functions and local macros in the current
  1701.   environment.  To see the definition of a local function or macro, use the
  1702.   function special form in the usual way.  That is, (function name) will
  1703.   return the definition of the local function or macro whose name is name.
  1704.   Local functions and local macros may be invoked as usual.
  1705.  
  1706.  
  1707. :blocks                                     [Break Loop Command]
  1708.  
  1709.   Prints the names of the blocks established in the current environment.  If
  1710.   a block block is established, then the return-from form (return-from block
  1711.   value) works as usual.  That is, the block form that established block will
  1712.   return value as its value and control will resume at that point.
  1713.  
  1714.  
  1715. :tags                                    [Break Loop Command]
  1716.  
  1717.   Prints the tags established in the current environment.  If a tag tag is
  1718.   established, then the go form (go tag) works as usual.  That is, control
  1719.   will resume at the position of tag in the surrounding tagbody.
  1720.  
  1721.  
  1722. :local &optional n                        [Break Loop Command]
  1723. :l &optional n                [Abbreviated Break Loop Command]
  1724.  
  1725.   If n is 0 or if it is omitted, then this command prints the value stored in
  1726.   the main stack entry that is pointed to by the current event environment.
  1727.   n is an offset from that entry.  If n is positive, then the value of the
  1728.   n-th next (i.e., toward the top of the main stack) entry is printed.  If n
  1729.   is negative, then the value of the | n |-th previous (i.e., toward the
  1730.   bottom of the main stack) entry is printed.  n must be an integer.  It is
  1731.   an error if the specified entry does not lie between the bottom and the top
  1732.   of the stack.
  1733.  
  1734.  
  1735. :hide symbol                             [Break Loop Command]
  1736.  
  1737.   Hides all events whose event symbol is symbol.  In particular, by (:hide
  1738.   'lambda) and (:hide 'lambda-closure), all events become invisible whose
  1739.   event functions are lambda-expressions and closures, respectively.  If the
  1740.   event symbol of the current event happens to be symbol, then the last
  1741.   previous visible event will become the new current event.  symbol must be a
  1742.   symbol.
  1743.  
  1744.   Events of eval and evalhook may never become invisible and attempts to hide
  1745.   them are simply ignored.  It is always the case that the first event
  1746.   function is either evalor evalhook.  Keeping both of them visible is the
  1747.   simplest way to avoid the silly attempts of the user to hide all events.
  1748.  
  1749.  
  1750. :hide-package package                      [Break Loop Command]
  1751.  
  1752.   Hides all events whose event symbol belongs to the package package.
  1753.   package may be any object that represents a package, i.e., a package
  1754.   object, a symbol, or a string.  If the event symbol of the current event
  1755.   happens to belong to the package package, then the last previous visible
  1756.   event will become the new current event.  Even if lisp package was
  1757.   specified as package, events of eval and evalhook do not become invisible.
  1758.   See the description of :hide above.
  1759.  
  1760.  
  1761. :unhide symbol                             [Break Loop Command]
  1762.  
  1763.   :unhide is the inverse command of :hide.  If, however, symbol belongs to
  1764.   one of the :hide-package'd packages, events of symbol become visible only
  1765.   after the package is :unhide-package'd.  symbol must be a symbol.
  1766.  
  1767.  
  1768. :unhide-package package[Break Loop Command]
  1769.  
  1770.   :unhide-package is the inverse command of :hide-package.  However, an event
  1771.   whose event symbol belongs to package becomes visible only after the symbol
  1772.   is :unhide'd, if the symbol was :hide'd before.  package may be any object
  1773.   that represents a package, i.e., a package object, a symbol, or a string.
  1774.  
  1775.  
  1776.      Example:
  1777.  
  1778.         >(defun fact (x) (if (= x 0) one (* x (fact (1- x)))))
  1779.         fact                    ;;; Wrong definition for fact, 
  1780.                                 the factorial.
  1781.         
  1782.         >(fact 6)               ;;; Tries to calculate factorial 6.
  1783.  
  1784.         Error: The variable ONE is unbound.
  1785.         Error signalled by IF.
  1786.         
  1787.         Broken at IF.           ;;; Enters the break-loop.
  1788.         >>:h                    ;;; Help.
  1789.         :c(urrent)              Shows the current function.
  1790.         :p(revious)             To the previous function.
  1791.         :n(ext)                 To the next function.
  1792.         :b(acktrace)            Prints backtrace.
  1793.         :h(elp)                 Help.
  1794.         :q(uit)                 Returns to top-level.
  1795.         :r(esume)               Returns to the caller of break-level.
  1796.         :l(ocal)                Shows the n-th local value on the stack.
  1797.         :v(ariables)            Shows local variables.
  1798.         :functions              Shows local functions.
  1799.         :blocks                 Shows block names.
  1800.         :tags                   Shows tags.
  1801.         :(un)hide(-package)     (Un)hide a function (or a package).
  1802.         
  1803.         >>:b                    ;;; Backtrace.
  1804.         Backtrace: eval > fact > if > fact > if > fact > if > fact > if >
  1805.         fact > if > fact > if > fact > IF
  1806.         
  1807.         >>:p                    ;;; Moves to the previous event.
  1808.         Broken at FACT.
  1809.         
  1810.         >>:b                    ;;; Now inside of fact 
  1811.                                 but outside of if.
  1812.         Backtrace: eval > fact > if > fact > if > fact > if > fact > if >
  1813.         fact > if > fact > if > FACT > if
  1814.         
  1815.         >>:v                    ;;; Shows local variables.
  1816.         Local variables: x.
  1817.         
  1818.         >>x                     ;;; The value of x 
  1819.                                 is 0.
  1820.         0
  1821.         
  1822.         >>:blocks               ;;; Shows blocks.
  1823.         Block names: fact.
  1824.         
  1825.         >>(return-from fact 1)  ;;; Returns from the fact 
  1826.                                 block with value 1.
  1827.         720                     ;;; Now the correct answer.
  1828.  
  1829.         >                       ;;; Top-level.
  1830.  
  1831.  
  1832. 5.5. Describe and Inspect
  1833.  
  1834. describe object                                    [Function]
  1835.  
  1836. Prints the information about object to the stream that is the value of
  1837. *standard-output*.  The description of an object consists of several
  1838. fields, each of which is described in a recursive manner.  For example, a
  1839. symbol may have fields such as home package, variable documentation, value,
  1840. function documentation, function binding, type documentation, deftype
  1841. definition, properties.
  1842.  
  1843.  
  1844. inspect object                                     [Function]
  1845.  
  1846. Prints the information about object in an interactive manner.  The output
  1847. of inspect is similar to that of describe, but after printing the label and
  1848. the value of a field (the value itself is not describe'd), it prompts the
  1849. user to input a one-character command.  The input to inspect is taken from
  1850. the stream that is the value of *query-io*.  Normally, the inspection of
  1851. object terminates after all of its fields have been inspected.  The
  1852. following commands are supported:
  1853.  
  1854. n       Next.  Goes to the next level; the field is inspected
  1855.                             recursively.
  1856.  
  1857. s       Skip.  Skips the inspection of the field.
  1858.                             inspect proceeds to the next field.
  1859.  
  1860. p       Print.  Pretty-prints the field and prompts again.
  1861.  
  1862. u form  Update.  The form is evaluated 
  1863.                              and the field is replaced by the resulting 
  1864.                             value.  If the field cannot be updated,
  1865.                             the message Not updated. will
  1866.                             be printed.
  1867.  
  1868. a       Abort.  Aborts the inspection of the current object.
  1869.                      The field and the rest of the fields
  1870.                      are not inspected.
  1871.  
  1872. e form  Eval.  Evaluates the specified 
  1873.                              form in the null environment and prints 
  1874.                              the resulting values.  Then prompts again with 
  1875.                              the same field.
  1876.  
  1877. q       Quit.  Aborts the entire inspection.
  1878.  
  1879. ?       Help.  Lists the inspect commands.
  1880.  
  1881.  
  1882.  
  1883.  
  1884.  
  1885.                      Chapter 6. The Compiler
  1886.  
  1887.  
  1888. The KCL compiler translates a Lisp program stored in a source file into a
  1889. C-language program, invokes the C-language compiler to compile the
  1890. C-language program, and then generates an object file, called fasl file (or
  1891. o-file because of the actual filetype).  The compiled program in a fasl
  1892. file is loaded by the function load.
  1893.  
  1894.      Ordinarily, the object program generated by the KCL compiler scarcely
  1895. does runtime error-checking for runtime efficiency.  In addition, Lisp
  1896. functions in the same source file are linked together and some system
  1897. functions are open-coded in-line.  To control runtime error checking,
  1898. supply appropriate optimize declarations (see Section 7.1).
  1899.  
  1900.      The KCL compiler processes the eval-when special form exactly as
  1901. specified in the Common Lisp Reference Manual.  However, all top-level
  1902. forms in the source file are normally processed in compile-time-too mode,
  1903. not in not-compile-time mode (see Section 5.3.3 of the Common Lisp
  1904. Reference Manual).  That is, each top-level form top-level-form is
  1905. processed as if it were surrounded by the eval-when special form with the
  1906. situations compile, load, and eval.
  1907.  
  1908.     (eval-when (compile load eval) top-level-form)
  1909.  
  1910. There is no exception for this rule.  Thus, for instance, in the example of
  1911. set-macro-character form in Section 5.3.3 of the Common Lisp Reference
  1912. Manual, the surrounding eval-when form is unnecessary in KCL.  If it is
  1913. desired that each top-level form be processed in not-compile-time mode,
  1914. change the value of the KCL specific variable *eval-when-compile* as
  1915. described below.
  1916.  
  1917.      The KCL compiler is invoked by the functions compile-file, compile,
  1918. and disassemble described below.  In addition, the KCL compiler may be
  1919. invoked directly by the Shell commands lc or lc1.  These commands require
  1920. the file name of the source file as their argument.  Both lc and lc1 simply
  1921. add ".lsp" to the file name argument to obtain the full name of the source
  1922. file.
  1923.  
  1924.         % lc filename
  1925.  
  1926. has the same effect as the compiler invocation (compile-file "filename")
  1927. from within KCL, and
  1928.  
  1929.         % lc1 filename
  1930.  
  1931. has the same effects as (compile-file "filename" :o-file t :c-file t
  1932. :h-file t :data-file t).
  1933.  
  1934.  
  1935. compile-file input-pathname                   [Function]
  1936.         &key :output-file :o-file :c-file :h-file :data-file
  1937.  
  1938. compile-file compiles the Lisp program stored in the file specified by
  1939. input-pathname, and generates a fasl file.  Also compile-file generates the
  1940. following temporary files.
  1941.  
  1942.         Temporary File  Contents
  1943.         ------------------------------------------------
  1944.         c-file          C version of the Lisp program
  1945.         h-file          The include file referenced 
  1946.                                          in the c-file
  1947.         data-file       The Lisp data to be used at load time
  1948.  
  1949. If files of these names already exist, the old files will be deleted first.
  1950. Usually, these intermediate files are automatically deleted after execution
  1951. of compile-file.
  1952.  
  1953.      The input-file is determined in the usual manner (see Section 2.9),
  1954. except that, if the filetype is not specified, then the default filetype
  1955. .lsp will be used.  The keyword parameter :output-file defines the default
  1956. directory and the default name to be applied to the output files (i.e., the
  1957. fasl file and the temporary files).  :output-file itself defaults to
  1958. input-pathname.  That is, if :output-file is not supplied, then the
  1959. directory and the name of the input file will be used as the default
  1960. directory and the default name for the output files.  The filetypes of the
  1961. output files are fixed as follows.
  1962.  
  1963.         Output File     Filetype
  1964.         ----------------------
  1965.         fasl file       .o
  1966.         c-file          .c
  1967.         h-file          .h
  1968.         data-file       .data
  1969.  
  1970. Each output file can be specified by the corresponding keyword parameter.
  1971. If the value of the keyword parameter is nil, then the output file will be
  1972. deleted after execution of compile-file.  If the value of the keyword
  1973. parameter is t, then the output file will be left in the default directory
  1974. under the default name.  Otherwise, the output file will be left in the
  1975. directory under the name specified by the keyword parameter.  The default
  1976. value of :o-file is t, and the default values of :c-file, :h-file, and
  1977. :data-file are all nil.
  1978.  
  1979.      Example:
  1980.  
  1981.         (compile-file 'foo)
  1982.                 The source file is "FOO.lsp" and 
  1983.                   the fasl file is "FOO.o"
  1984.                 both in the current directory.
  1985.  
  1986.         (compile-file 'foo.lish)
  1987.                 The source file is "FOO.LISH" and 
  1988.                  the fasl file is "FOO.o".
  1989.  
  1990.         (compile-file "/usr/mas/foo" :output-file "/usr/tai/baa")
  1991.                 The source file is "foo.lsp" in the 
  1992.                    directory "/usr/mas",
  1993.                 and the fasl file is "baa.o" in the 
  1994.                  directory "/usr/tai".
  1995.  
  1996.  
  1997. ----------------------Note to KCL/AOS users----------------------
  1998.  
  1999. The compiler of KCL/AOS generates the following output files.
  2000.  
  2001.         Output File     Filetype                Contents
  2002.         ------------------------------------------------------------
  2003.         fasl file       .fasl           The fasl file
  2004.         c-file          .c              C version of the Lisp program
  2005.         h-file          .h              The include file referenced 
  2006.                                         in the c-file 
  2007.         ob-file         .ob             The object file generated by 
  2008.                                          the C compiler
  2009.         data-file       .data           The Lisp data to be 
  2010.                                           used at load time
  2011.  
  2012. Note that the filetype of the fasl file is .fasl in KCL/AOS.  Also note
  2013. that the compiler of KCL/AOS generates an additional file ob-file.
  2014. Accordingly, the function compile-file has a slightly different definition:
  2015.  
  2016. compile-file input-pathname                       [Function] 
  2017.         &key :output-file :fasl-file :c-file :h-file :ob-file :data-file
  2018.  
  2019. The keyword parameter :fasl-file corresponds to the keyword parameter
  2020. :o-file in KCL on Unix.  In particular, the default value of :fasl-file is
  2021. t and the default values of :c-file, :h-file, :ob-file, and :data-file are
  2022. all nil.  In KCL/AOS,
  2023.  
  2024.         ) lc1 filename
  2025.  
  2026. has the same effects as (compile-file "filename" :fasl-file t :c-file t
  2027. :h-file t :ob-file t :data-file t).
  2028.  
  2029.      Because KCL/AOS follows the convention of the AOS/VS file system, the
  2030. last example above should be replaced as:
  2031.  
  2032.         (compile-file ":udd:mas:foo" :output-file ":udd:tai:baa")
  2033.                 The source file is "FOO.LSP" in the 
  2034.                 directory ":UDD:MAS",
  2035.                 and the fasl file is "BAA.FASL" in the 
  2036.                 directory ":UDD:TAI".
  2037.  
  2038. ---------------------------End of Note----------------------------
  2039.  
  2040.  
  2041. compile name &optional definition                  [Function]
  2042.  
  2043.   If definition is not supplied, name should be the name of a
  2044.   not-yet-compiled function.  In this case, compile compiles the function,
  2045.   replaces the previous definition of name with the compiled function, and
  2046.   returns name.  If definition is supplied, it should be a lambda-expression
  2047.   to be compiled and name should be a symbol.  If name is a non-nil symbol,
  2048.   then compile installs the compiled function as the function definition of
  2049.   name and returns name.  If name is nil, then compile simply returns the
  2050.   compiled function.
  2051.  
  2052.        The KCL compiler is essentially a file compiler, and forms to be
  2053.   compiled are supposed to be stored in a file.  Thus compile actually
  2054.   creates a source file which contains the form designated by the arguments.
  2055.   Then compile calls compile-file to get a fasl file, which is then loaded
  2056.   into KCL.  The source file and the fasl file are given the names gazonk.lsp
  2057.   and gazonk.fasl, respectively.  These files are not deleted automatically
  2058.   after the execution of compile.
  2059.  
  2060.  
  2061. disassemble &optional thing &key :h-file :data-file     [Function]
  2062.  
  2063.   This function does not actually disassemble.  It always calls the KCL
  2064.   compiler and prints the contents of the c-file, i.e., the C-language code,
  2065.   generated by the KCL compiler.  If thing is not supplied, or if it is nil,
  2066.   then the previously compiled form by disassemble will be compiled again.
  2067.   If thing is a symbol other than nil, then it must be the name of a
  2068.   not-yet-compiled function, whose definition is to be compiled.  In this
  2069.   case, it is an error if the name is associated with a special form or a
  2070.   macro.  If thing is a lambda-expression (lambda lambda-list . body), then
  2071.   disassemble first creates a function definition (defun gazonk lambda-list .
  2072.   body) and this definition is compiled.  (The function name gazonk has no
  2073.   special meanings.  Indeed, the displayed code is essentially independent of
  2074.   the function name.)  Otherwise, thing itself will be compiled as a
  2075.   top-level form.  In any case, disassemble does not install the compiled
  2076.   function.  disassemble returns no value.
  2077.  
  2078.       No intermediate h-file is created if the keyword parameter :h-file is
  2079.   nil or if :h-file is not supplied.  Otherwise, an intermediate h-file is
  2080.   created under the name specified by :h-file.  Similarly, the intermediate
  2081.   data-file is specified by the keyword parameter :data-file.
  2082.  
  2083.  
  2084. *eval-when-compile*                           [Variable]
  2085.  
  2086.   The compiler processes each top-level form in not-compile-time mode if the
  2087.   value of this variable is nil, and in compile-time-too mode, otherwise.
  2088.   See Section 5.3.3 of Common Lisp Reference Manual for these two modes.  The
  2089.   initial value of this variable is t.
  2090.  
  2091.  
  2092.  
  2093.  
  2094.                           Chapter 7. Declarations
  2095.  
  2096.  
  2097. KCL supports all kinds of declarations described in the Common Lisp
  2098. Reference Manual.  Any valid declaration will affect the KCL environment in
  2099. some way or another, although information obtained by declarations, other
  2100. than special declarations, is mainly used by the KCL compiler.
  2101.  
  2102.      As described in the Common Lisp Reference Manual, Common Lisp
  2103. declarations are divided into two classes: proclamations and others.  A
  2104. proclamation is a global declaration given by the function proclaim, the
  2105. top-level macro defvar, or the top-level macro defparameter.  Once given, a
  2106. proclamation remains effective during the KCL session unless it is shadowed
  2107. by a local declaration or is canceled by another proclamation.  Any other
  2108. declaration is a local declaration and is given only by the special form
  2109. declare.  A local declaration remains in effect only within the body of the
  2110. construct that surrounds the declaration.  In the following nonsensical
  2111. example borrowed from Chapter 9 of the Common Lisp Reference Manual,
  2112.  
  2113.     (defun nonsense (k x z)
  2114.       (foo z x)
  2115.       (let ((j (foo k x))
  2116.             (x (* k k)))
  2117.            (declare (inline foo) (special x z))
  2118.         (foo x j z)))
  2119.  
  2120. the inline and the special declarations both remain in effect within the
  2121. surrounding let form.  In this case, we say that the let form is the
  2122. surrounding construct of these declarations.
  2123.  
  2124. proclamation decl-spec                           [Function]
  2125.  
  2126. This function is introduced to KCL so that the user can see currently
  2127. effective proclamations.  The argument decl-spec specifies the proclamation
  2128. to be checked.  It may be any declaration specification that can be a valid
  2129. argument to the function proclaim.  The function proclamation returns t if
  2130. the specified proclamation is still in effect.  Otherwise, it returns nil.
  2131. For example,
  2132.  
  2133.     >(proclaim '(special *x*))  ;;; The variable *x* is
  2134.     nil                         ;;; proclaimed to be globally special.
  2135.  
  2136.     >(proclamation '(special *x*))
  2137.     t
  2138.  
  2139.     >(defvar *y*)               ;;; Another way to proclaim a variable
  2140.     nil                         ;;; to be globally special.
  2141.  
  2142.     >(proclamation '(special *y*))
  2143.     t
  2144.  
  2145.  
  2146. the value-type form                          [Special Form]
  2147.  
  2148. The KCL interpreter does actually check whether the value of the form
  2149. conforms to the data type specified by value-type and signals an error if
  2150. the value does not.  The type checking is performed by the function typep.
  2151. For example,
  2152.  
  2153.     (the fixnum (foo))
  2154.  
  2155. is equivalent to
  2156.  
  2157.  (let ((values (multiple-value-list (foo))))
  2158.    (cond ((endp values) (error "Too few return values."))
  2159.          ((not (endp (cdr values)))
  2160.           (error "Too many return values."))
  2161.          ((typep (car values) 'fixnum) (car values))
  2162.          (t (error "~s is not of type fixnum." (car values)))))
  2163.  
  2164. On the other hand, the KCL compiler uses the the special form to obtain
  2165. type information for compiled code optimization.  No code for runtime
  2166. type-checking is embedded in the compiled code.
  2167.  
  2168.  
  2169. 7.1. Declaration Specifiers
  2170.  
  2171. KCL recognizes all declaration specifiers defined in the Common Lisp
  2172. Reference Manual.  The syntax of each such declaration specifier is exactly
  2173. the same as defined in the Common Lisp Reference Manual.  In addition, KCL
  2174. recognizes the object declaration specifier which is specific to KCL.
  2175.  
  2176. special { variable-name }*                [Declaration Specifier]
  2177.  
  2178. The interpreter and the compiler of KCL both treat special declarations
  2179. exactly as described in the Common Lisp Reference Manual.
  2180.  
  2181.  
  2182. type type { variable-name }*              [Declaration Specifier]
  2183.  
  2184. A type proclamation (type type var1 var2 ...) specifies that the dynamic
  2185. values of the named variables are of the type type.  A local type
  2186. declaration specifies that the variables mentioned are bound by the
  2187. surrounding construct and have values of the type type during execution of
  2188. the surrounding construct.  The compiler issues a warning if one of the
  2189. named variables is not bound by the surrounding construct.  The information
  2190. given by type declarations is used by the compiler to optimize the compiled
  2191. code.  The behavior of the compiled code is unpredictable if a wrong type
  2192. declaration is supplied.  The compiler detects certain wrong type
  2193. declarations at compile time.  For example,
  2194.  
  2195.         >(defun foo (x y)
  2196.            (declare (fixnum x) (character y))
  2197.            (setq x y)
  2198.           ...))
  2199.         foo
  2200.  
  2201.         >(compile 'foo)
  2202.  
  2203.         ; (defun foo ...) is being compiled.
  2204.         ;; Warning: Type mismatches between x and y.
  2205.  
  2206. See Section 7.3 for further information on type declarations.
  2207.  
  2208.  
  2209. type { variable-name }*              [Declaration Specifier]
  2210.  
  2211. (type var1 var2 ...) is equivalent to (type type var1 var2 ...), provided
  2212. that type is one of the symbols in Table 4-1 of the Common Lisp Reference
  2213. Manual, other than function.  Declaration specifications that begin with
  2214. function are regarded as function declarations (see below).
  2215.  
  2216.  
  2217. function function-name argument-types . return-types [Declaration Specifier]
  2218.  
  2219. A function declaration is used to obtain type information for function call
  2220. forms.  That is, a function declaration specifies the argument and the
  2221. return types of each form that calls the named function.
  2222.  
  2223.     (defun foo ()
  2224.       (declare (function bar (character) fixnum))
  2225.       (+ (bar (atcholi1)) (bar (atcholi2))))
  2226.  
  2227. In this example, the function declaration specifies that the two functions
  2228. atcholi1 and atcholi2 both return character objects when called within the
  2229. body of foo, and that the function bar returns fixnum objects when called
  2230. within the body of foo.  The type information given by function
  2231. declarations is used by the compiler to optimize the compiled code.  The
  2232. behavior of the compiled code is unpredictable if a wrong function
  2233. declaration is supplied.  The compiler detects certain wrong function
  2234. declarations at compile time.  For example,
  2235.  
  2236.     >(defun foo (x)
  2237.        (declare (fixnum x)
  2238.                 (function bar (character) fixnum))
  2239.        (bar x))
  2240.     foo
  2241.  
  2242.     >(compile 'foo)
  2243.  
  2244.     ; (defun foo ...) is being compiled.
  2245.     ;; Warning: The type of the form x is not character.
  2246.  
  2247. However, the compiler does not check the number of arguments, and thus,
  2248. the following function definition will be compiled successfully without
  2249. any warnings.
  2250.  
  2251.     (defun foo ()
  2252.       (declare (function bar (character character) fixnum))
  2253.       (+ (bar (atcholi1)) (bar (atcholi2) (atcholi3) (atcholi4))))
  2254.  
  2255. For this definition, the compiler assumes that the three functions
  2256. atcholi1, atcholi2, and atcholi3 will return fixnum objects.  The return
  2257. type of atcholi4 is unknown at compile time.
  2258.  
  2259. The complete syntax of a function declaration is:
  2260.  
  2261.     (function function-name
  2262.       ( { type }* [ { &optional | &rest | &key } { thing }* ] )
  2263.       { (values { type }* ) | { type }* }
  2264.      )
  2265.  
  2266. Although &optional, &rest, and &key markers may appear in the list of
  2267. argument types, only those types are recognized that appear before any such
  2268. markers and the rest of the list is simply ignored.  Note that functions
  2269. with &optional, &rest, or &key parameters may still be declared by function
  2270. declarations because of the use of function declarations mentioned above.
  2271.  
  2272. The values construct in the specification of return types is almost
  2273. useless:  (function function-name argument-types (values type1 type2 ...))
  2274. is equivalent to (function function-name argment-types type1 type2 ...).
  2275. We, the implementors of KCL wonder why the value construct was introduced
  2276. in Common Lisp.
  2277.  
  2278. See Section 7.3 for further information on function declarations.
  2279.  
  2280.  
  2281. ftype function-type { function-name }*     [Declaration Specifier]
  2282.  
  2283. function-type must be a list whose first element is the symbol function.
  2284. (ftype (function . rest) function-name-1 ... function-name-n) is equivalent
  2285. to n consecutive function declarations (function function-name-1 . rest)
  2286. ...  (function function-name-n . rest).
  2287.  
  2288.  
  2289. notinline { function-name }*          [Declaration Specifier]
  2290.  
  2291. (notinline function1 function2 ...) specifies that the compiler should not
  2292. compile the named functions in-line.  Calls to the named functions can be
  2293. traced and an event (see Section 5.4) is pushed on the event stack when any
  2294. one of the named functions is invoked.
  2295.  
  2296.  
  2297. inline { function-name }*                 [Declaration Specifier]
  2298.  
  2299. An inline proclamation cancels currently effective notinline proclamations,
  2300. and a local inline declaration locally shadows currently effective
  2301. notinline declarations.
  2302.  
  2303.     >(defun foo (x)
  2304.        (cons (car x)
  2305.              (locally (declare (inline car)) (car x))))
  2306.     foo
  2307.  
  2308.     >(defun bar (x)
  2309.        (cons (car x)
  2310.              (locally (declare (inline car)) (car x))))
  2311.     foo
  2312.  
  2313.     >(proclaim '(notinline car))
  2314.     nil
  2315.  
  2316.     >(compile 'foo)
  2317.     ...
  2318.  
  2319.     >(proclaim '(inline car))
  2320.     nil
  2321.  
  2322.     >(compile 'bar)
  2323.     ...
  2324.  
  2325. Usually, primitive functions such as car are compiled in-line.  Therefore,
  2326. in this example, only the first call to car within foo is compiled not
  2327. in-line,
  2328.  
  2329. In general, the KCL compiler compiles functions in-line whenever possible.
  2330. Thus an inline declaration (inline function1 function2 ...) is worthless if
  2331. none of the named functions have previously been declared to be notinline.
  2332.  
  2333.  
  2334. ignore { variable-name }*             [Declaration Specifier]
  2335.  
  2336. Usually, the compiler issues a warning if a lexical variable is never
  2337. referred to.  (ignore var1 ... varn) causes the compiler not to issue a
  2338. warning even if the named variables are never referred to.  The compiler
  2339. issues a warning if one of the named variables is not bound by the
  2340. surrounding construct, or if a named variable is actually referred to.
  2341. ignore proclamations are simply ignored.
  2342.  
  2343.  
  2344. optimize { { (quality value) | quality } }*    [Declaration Specifier]
  2345.  
  2346. KCL supports the four optimize qualities listed in the Common Lisp
  2347. Reference Manual.  speed and compilation-speed are used to set up the
  2348. optimization switch of the C language compiler which is invoked to compile
  2349. the C-language code generated by the KCL compiler (see Chapter 6).
  2350. (optimize (speed n)) and (optimize (compilation-speed m)) are equivalent,
  2351. where n and m are integers between 0 and 3, and m is equal to 3-n.  When a
  2352. KCL session is started, the speed quality is set to 3.  That is, by
  2353. default, the compiler generates the fastest code in the longest compilation
  2354. time.  The space quality specifies whether the code size is important or
  2355. not:  The compiled code is a little bit larger and faster when compiled
  2356. with the space quality 0, than when compiled with the space quality 1, 2,
  2357. or 3.  When a KCL session is started, the space quality is set to 0.  The
  2358. safety quality determines how much runtime error checking code should be
  2359. embedded in the compiled code.  If the safety quality is 0, the compiled
  2360. code scarcely does runtime error checking.  If the safety quality is 1,
  2361. then the compiled code for a function will check the number of arguments to
  2362. the function at runtime.  If the safety quality is 2 or 3, then the
  2363. compiled code does full runtime error checking.  In addition, the highest
  2364. quality value 3 causes the compiler to treat all functions as if they were
  2365. declared to be notinline.  When a KCL session is started, the safety
  2366. quality is set to 0.
  2367.  
  2368.  
  2369. declaration ) { name }*                      [Declaration Specifier]
  2370.  
  2371. A declaration declaration is used exactly as specified in the
  2372. Common Lisp Reference Manual.
  2373.  
  2374.  
  2375. object { variable-name }*                    [Declaration Specifier]
  2376.  
  2377. This is the only declaration specifier that is specific to KCL.  (object
  2378. var1 ... varn) affects only variable bindings and specifies that the named
  2379. variables can be allocated in the C stack (see Section 7.3).  The compiler
  2380. issues a warning if one of the named variables is not bound by the
  2381. surrounding construct.  object proclamations are simply ignored.
  2382.  
  2383.  
  2384. 7.2. Significant Type Specifiers
  2385.  
  2386. Whenever a declaration is encountered, each type specifier (if any) in the
  2387. declaration is converted to one of the following type specifiers, which are
  2388. collectively called the significant type specifiers.
  2389.  
  2390.           ------------  fixnum 
  2391.           |
  2392.           ------------  character 
  2393.           |
  2394.           ------------  short-float 
  2395.           |
  2396.           ------------  long-float 
  2397.           |
  2398.      t  ----  (array t)  ------------  (vector t) 
  2399.           |
  2400.           --  (array fixnum)  -------  (vector fixnum) 
  2401.           |
  2402.           --  (array string-char)  --  string  
  2403.           |
  2404.           --  (array short-float)  --  (vector short-float)
  2405.           |
  2406.           --  (array long-float)  ---  (vector long-float) 
  2407.           |
  2408.           --  (array bit)  ----------  bit-vector 
  2409.  
  2410. Here, the lines indicate subtype relations; the right type is a subtype of
  2411. the left type.  For instance, (vector t) is a subtype of (array t) and t,
  2412. and (array t) itself is a subtype of t.  However, (array t) and (array
  2413. string-char) are disjoint types.
  2414.  
  2415.      The function subtypep is used for the conversion to significant type
  2416. specifiers:  If the first value of (subtypep raw-type type) is t for one of
  2417. the significant type specifiers type, then the type specifier raw-type in
  2418. the declaration is converted to type.  If there are more than one such
  2419. significant type specifiers, then the type specifier that is a subtype of
  2420. other specifiers is selected.  For example, type specifiers fixnum, (mod
  2421. 3), and (member 0 1) are all converted to fixnum, though they are also
  2422. subtypes of t.
  2423.  
  2424.      Because of this type specifier conversion, KCL may sometimes regard
  2425. two seemingly distinct declarations as the same.  For example, the
  2426. following type declarations are completely equivalent, internally in KCL.
  2427.  
  2428.     (declare (type fixnum x))
  2429.  
  2430.     (declare (type (mod 3) x))
  2431.  
  2432.     (declare (type (member 0 1) x))
  2433.  
  2434. Type specifiers in declaration specifications passed to the KCL specific
  2435. function proclamation are also converted to significant type specifiers.
  2436. Thus, for example,
  2437.  
  2438.     >(proclaim '(function foo (fixnum) fixnum))
  2439.     nil
  2440.  
  2441.     >(proclamation '(function foo ((mod 3)) (member 0 1)))
  2442.     t
  2443.  
  2444.     >(proclamation '(function foo (number) character))
  2445.     nil
  2446.  
  2447. The first call to proclamation returns t because both (mod 3) and (member 0
  2448. 1) are converted to fixnum before the function type of foo is checked.
  2449.  
  2450.  
  2451. 7.3. Treatment of Type Declarations
  2452.  
  2453. KCL has several runtime stacks.  One of them is called the value stack
  2454. which is the "main stack" of KCL:  Arguments to functions and resulting
  2455. values of functions are usually passed via the value stack, lexical
  2456. variables in compiled code are usually allocated on the value stack, and
  2457. temporary values during evaluation of nested expressions are usually saved
  2458. on the value stack.  However, if appropriate declarations are supplied to
  2459. the compiler, the compiled code will use another stack called the C stack,
  2460. which can be accessed more efficiently than the value stack.  In addition,
  2461. arguments and resulting values passed via the C stack, values of lexical
  2462. variables allocated on the C stack, and temporary values saved on the C
  2463. stack may sometimes be represented as raw data instead of pointers to
  2464. heap-allocated cells.  In KCL, even a fixnum object is usually represented
  2465. as a pointer to a fixnum cell in which the raw datum (i.e., the 32-bit
  2466. signed integer) for the fixnum is stored.  Accessing such raw data on the C
  2467. stack results in faster compiled code, partly because no pointer
  2468. deferencing operation is necessary, and partly because no cell is newly
  2469. allocated on the heap when a new object is created.  In contrast, any
  2470. object on the value stack is represented as a pointer to a heap-allocated
  2471. cell.
  2472.  
  2473.      One of the deficiencies of the use of the C stack is that raw data on
  2474. the C stack may sometimes need to be reallocated on the heap.  Suppose, in
  2475. the following example, that the lexical variable x is allocated on the C
  2476. stack and has always a fixnum raw datum as its value.  (The situations in
  2477. which this occurs will be explained later.)
  2478.  
  2479.     (defun foo ()
  2480.       (let ((x 0))
  2481.         ....
  2482.         (bar x)
  2483.         ....
  2484.         ))
  2485.  
  2486. Also suppose that the function bar expects its argument to be passed via
  2487. the value stack rather than via the C stack.  (This situation typically
  2488. occurs when foo and bar are defined in separate source files.  See below.)
  2489. On call to bar, the compiled code of foo will allocate a fixnum cell on the
  2490. heap and push the pointer to this cell on the value stack as the argument
  2491. to bar.
  2492.  
  2493.      Another deficiency is that it is sometimes dangerous to allocate a
  2494. cell pointer onto the C stack.  (This occurs when object) declarations are
  2495. supplied.  See below.)  The garbage collector of KCL never takes care of
  2496. cell pointers on the C stack and thus a heap-allocated cell pointed to only
  2497. from the C stack may be recycled for further use, while the data in the
  2498. cell is still in use.  This is why KCL usually uses the less efficient
  2499. value stack.  In contrast, objects on the value stack are automatically
  2500. protected against garbage collection.  Note that raw data on the C stack
  2501. need not be protected against garbage collection because they remain alive
  2502. until the C stack is popped.
  2503.  
  2504.  
  2505. 7.3.1. Variable Allocations
  2506.  
  2507. If a lexical variable is declared to be of fixnum, character, short-float,
  2508. long-float, or their subtypes, then it is allocated on the C stack rather
  2509. than on the value stack.  In addition, the variable always has a raw datum
  2510. as its value: 32 bit signed integer for fixnums, 8 bit character code with
  2511. 24 bit padding for characters (remember that the font and bit fields of KCL
  2512. characters are always 0), 32 bit floating point representation for
  2513. short-floats, and 64 bit floating point representation for long-floats.
  2514. Similarly, if a lexical variable is named in an object declaration (see
  2515. Section 7.1), then it is allocated on the C stack but, in this case, the
  2516. variable always has a cell pointer as its value.  The user is strongly
  2517. recommended to make sure that objects stored in such an object variable may
  2518. never be garbage collected unexpectedly.  For example,
  2519.  
  2520.     (do ((x (foo) (cdr x)))
  2521.         ((endp x))
  2522.         (let ((y (car x)))
  2523.              (declare (object y))
  2524.           (bar y)))
  2525.  
  2526. this object declaration is completely safe because the value of the
  2527. variable y is always a substructure of the value of x, which in turn is
  2528. protected against garbage collection.  Incidentally, loop variables of
  2529. dolist may always be declared as object variables, since the dolist form
  2530. has essentially the same control structure as the do form above.  On the
  2531. other hand, the result of evaluation of the following form is
  2532. unpredictable, because the cons cell pointed to from the object variable z
  2533. may be garbage collected before bar is called.
  2534.  
  2535.     (let ((z (cons x y)))
  2536.          (declare (object z))
  2537.       (foo (cons x y))
  2538.       (bar z))
  2539.  
  2540.      Lexical variables that are not declared to be of fixnum, character,
  2541. short-float, long-float, or their subtypes, and that are not named in
  2542. object declarations are usually allocated on the value stack, but may
  2543. possibly be allocated on the C stack automatically by the compiler.
  2544.  
  2545.  
  2546. 7.3.2. Built-in Functions that Operate on Raw Data Directly 
  2547.  
  2548. Some built-in Common Lisp functions can directly operate on raw data, if
  2549. appropriate declarations are supplied.  The addition function + is
  2550. among such functions.
  2551.  
  2552.     (let ((x 1))
  2553.          (declare (fixnum x))
  2554.       ....
  2555.       (setq x (+ x 2))
  2556.       ....
  2557.       )
  2558.  
  2559. In the compiled code for this let form, the raw fixnum datum (i.e., the 32
  2560. bit signed integer) stored in x is simply incremented by 2 and the
  2561. resulting 32 bit signed integer is stored back into x.  The compiler is
  2562. sure that the addition for 32 bit signed integers will be performed on the
  2563. call to +, because the arguments are both fixnums and the return value must
  2564. be also a fixnum since the value is to be assigned to the fixnum variable.
  2565. The knowledge of both the argument types and the return type is necessary
  2566. for this decision:  Addition of two fixnums may possibly produce a bignum
  2567. and addition of two bignums may happen to produce a fixnum value.  If
  2568. either the argument type or the return type were not known to the compiler,
  2569. the general addition function would be called to handle the general case.
  2570. In the following form, for example, the compiler cannot be sure that the
  2571. return value of the multiplication is a fixnum or that the arguments of the
  2572. addition are fixnums.
  2573.  
  2574.     (setq x (+ (* x 3) 2))
  2575.  
  2576. In order to obtain the optimal code, a the special form should surround the
  2577. multiplication.
  2578.  
  2579.     (setq x (+ (the fixnum (* x 3)) 2))
  2580.  
  2581.  
  2582.      Built-in Common Lisp functions that can directly operate on raw data
  2583. are:
  2584.  
  2585. 1. arithmetic functions such as +, -, 1+, 1-, *, floor, mod, /, and expt.
  2586.  
  2587. 2. predicates such as eq, eql, equal, zerop, plusp, minusp, =, /=, <, <=,
  2588. >, >=, char=, char/, char<, char<=, char>, and char>=.
  2589.  
  2590. 3. sequence processing functions that receive or return one or more fixnum
  2591. values, such as nth, nthcdr, length, and elt.
  2592.  
  2593. 4. array access function such as svref, char, schar, and aref (see below).
  2594.  
  2595. 5. system-internal functions for array update (see below).
  2596.  
  2597. 6. type-specific functions such as char-code, code-char, and float.
  2598.  
  2599.      As mentioned in Section 2.5.1, array elements are represented in one
  2600. of the six ways depending on the type of the array.  By supplying
  2601. appropriate array type declarations, array access and update operations can
  2602. handle raw data stored in arrays.  For example,
  2603.  
  2604.      (let ((a (make-array n :element-type 'fixnum))
  2605.            (sum O))
  2606.           (declare (type (array fixnum) a)
  2607.                    (fixnum sum))
  2608.        (dotimes (i n)             ;;; Array initialization.      
  2609.                 (declare (fixnum i))  
  2610.           (setf (aref a i) i))
  2611. ....
  2612. (dotimes (i n)                    ;;;Summing up the elements.
  2613.          (declare (fixnum i))
  2614.   (setq sum (+ (aref a i) sum )))      
  2615. ....
  2616. )
  2617.  
  2618. The setf form replaces the i-th element of the array a by the raw fixnum
  2619. value of i.  The aref form retrieves the raw fixnum datum stored in a.
  2620. This raw datum is then added to the raw fixnum value of the fixnum variable
  2621. sum, producing the raw fixnum datum to be stored in sum.  The similar raw
  2622. data handling is possible for arrays of types (array fixnum), (vector
  2623. fixnum), (array string-char), and (vector long-float).
  2624.  
  2625.  
  2626. 7.3.3.Arguments/Values Passing
  2627.  
  2628. Function proclamations (function funtion-name (arg-type1 arg-type2...)
  2629. return-type ) or its equivalents give the compiler the chance to generate
  2630. the compiled code so that arguments to the named functions and resulted
  2631. values of the named function be passed via the C stack, thus increasing the
  2632. efficiency of calls to these functions.  Such arguments/values passing via
  2633. the C stack is possible only if the called function is also defined in the
  2634. same source file.  This is because the code for the called function must
  2635. have two entries:  One entry for arguments/values passing via the C stack
  2636. and another for arguments/values passing via the value stack.  (An ordinary
  2637. function has only the latter entry.)  When the latter entry is used, the
  2638. arguments on the value stack are pushed onto the C stack and then the
  2639. former entry is used to execute the body of the function.  On return from
  2640. the function, the resulted value on the C stack is pushed onto the value
  2641. stack.  This means that ordinary calls to these functions are slower than
  2642. calls to ordinary functions.
  2643.  
  2644. One of the merits of arguments/values passing via the C stack is that raw
  2645. data stored on C-stack-allocated variables can be passed directly to other
  2646. functions and raw data returned from functions may be directly saved in
  2647. C-stack-allocated variables or may directly be used as arguments to another
  2648. function.  A good example of this follows:
  2649.  
  2650. (eval-when (compile)
  2651.    (proclaim '(function tak (fixnum fixnum fixnum) fixnum)))
  2652.  
  2653. (defun tak (x y z)
  2654.    (declare (fixnum x y z))
  2655.    (if (not (< y x))
  2656.        z
  2657.        (tak (tak (1- x) y z)
  2658.             (tak (1- y) z x)
  2659.             (tak (1- z) x y))))
  2660.  
  2661. ;;; Call (tak 18 12 6).
  2662.  
  2663. When tak is called with the arguments 18, 12, and 6, the raw fixnum data of
  2664. the arguments are set to the parameters x, y, z which are allocated on the
  2665. C stack.  After that, only raw data on the C stack are used to perform the
  2666. execution:  No cell pointers are newly allocated nor even referenced.
  2667. Arguments and resulted values for recursive calls to tak are passed via the
  2668. C stack, and the built-in functions < and 1- directly operate on the raw
  2669. data.  Only at the return from the top-level call of tak, the resulted raw
  2670. data value (which happens to be 7) is reallocated on the heap.  Note that
  2671. both the functions proclamation and the local fixnum declaration are
  2672. necessary to obtain the optimal code.  The function proclamation is
  2673. necessary for arguments/values passing via the C stack and the fixnum
  2674. declarations is necessary to allocate the parameters onto the C stack.
  2675.  
  2676.  
  2677.  
  2678.  
  2679.                Chapter 8. Operating System Interface
  2680.  
  2681.      KCL provides the following facilities that are not defined in the
  2682. Common Lisp Reference Manual.
  2683.  
  2684. save filename                                  [Function]
  2685.  
  2686. save saves the current memory image into a program file filename.  After
  2687. saving the memory image, the KCL process terminates immediately.  To
  2688. execute the saved program file, specify the full pathname of the file, as
  2689. indicated in the example below.
  2690.  
  2691.  
  2692. ---------------------------Note to KCL/AOS Users-----------------------------
  2693.  
  2694. In KCL/AOS, if the filename does not contain the filetype .pr, then the
  2695. program file is given the name filename.pr.  Also save saves a symbol table
  2696. file with the filetype .st.  When the program file is executed, execution
  2697. begins at the top-level of KCL.  Even if there were streams that were open
  2698. at the call of save, these streams are not effective when the program file
  2699. is executed.  The function save of KCL/AOS does no terminate the KCL
  2700. process.
  2701.  
  2702. -------------------------End of Note------------------------------------
  2703.  
  2704.  
  2705. Example:
  2706.  
  2707. >(defun plus (x y) (+x y))
  2708. plus
  2709.  
  2710. >(save "savefile")
  2711. %
  2712.  
  2713. %pwd
  2714. /usr/hagiya/savefile
  2715.  
  2716. >(plus 2 3)
  2717. 5
  2718. >(bye)
  2719. Bye.
  2720. %
  2721.  
  2722. -------------------Note to KCL/AOS users--------------------------
  2723.  
  2724. Here is the example of save in KCL/AOS.
  2725.  
  2726.   >(defun plus (x y) (+x y))
  2727.   plus
  2728.  
  2729.   >(save "savefile")
  2730.   t
  2731.  
  2732.   >(bye)
  2733.   Bye.
  2734.   )
  2735.  
  2736.   ) X SAVEFILE
  2737.  
  2738.   >(plus 2 3)
  2739.   5
  2740.  
  2741.   >(bye)
  2742.   Bye.
  2743.   )
  2744.  
  2745. ----------------------------End of Note-------------------------------
  2746.  
  2747.  
  2748. system string                                          [Function]
  2749.  
  2750. Executes a Shell command as if string is an input to the Shell.  On return
  2751. from the Shell command, system returns the exit code of the command as an
  2752. integer.
  2753.  
  2754.  
  2755. ----------------------Note to KCL/AOS Users-----------------------
  2756.  
  2757. This function is not suppported in KCL/AOS.  Use instead those functions
  2758. specific to KCL/AOS described below.
  2759.  
  2760. -------------------------End of Note--------------------------------
  2761.  
  2762.  
  2763. bye &optional exit-code                             [Function]
  2764. by  &optional exit-code                             [Function]
  2765.  
  2766.      Terminates KCL and returns the exit-code to the parent process.
  2767. exit-code must be an integer and its default value is O.
  2768.  
  2769.  
  2770. -----------------------Note to KCL/AOS Users--------------------------
  2771.  
  2772. The functions bye and by of KCL/AOS accept a string instead of an
  2773. exit-code.  If string is supplied, these functions return the string to the
  2774. father as the termination message.
  2775.  
  2776. ---------------------------End of Note-----------------------------
  2777.  
  2778.  
  2779. The following functions process, termination-message, and
  2780. last-termination-message are specific to KCL/AOS and are not supported in
  2781. KCL on Unix.
  2782.  
  2783. process progname &optional ipc-message                 [Function]
  2784.                  &key :block :console :debug :dir
  2785.                  :input :output :username
  2786.                  :list :data :ioc
  2787.  
  2788.      This function is defined only in KCL/AOS.  process creates a 
  2789. process in the way as specified by its arguments.
  2790.  
  2791.      progname             The name of the process to create.  
  2792.                           Must be a string
  2793.      
  2794.      ipc-message          The IPC message passed to the process.  
  2795.                           Must be a string.  Arguments in the 
  2796.                           message must be separated with commas 
  2797.                           `,'.
  2798.  
  2799.      :block               If non-nil, Kcl blocks its execution 
  2800.                           while the son executes.  Defaults to t.
  2801.  
  2802.      :console             The name of the file to be associated 
  2803.                           to @console.  Must be a string.  No 
  2804.                           file is associated if :console is not 
  2805.                           specified and if the :ioc argument (see 
  2806.                           below) is specified with a non-nil 
  2807.                           value.  :console supercedes :ioc.
  2808.  
  2809.      :debug               If non-nil, the son runs in the debug 
  2810.                           mode.
  2811.  
  2812.      :input               The name of the file to be associated 
  2813.                           to @input.  Must be string.  No file is 
  2814.                           associated if :input is not specified 
  2815.                           and if the :ioc argument (see below) is 
  2816.                           specified with a non-nil value.  :input 
  2817.                           supercedes :ioc.
  2818.  
  2819.      :output              The name of the file to be associated 
  2820.                           to @output.  Must be a string.  No file 
  2821.                           is associated if :output is not 
  2822.                           specified and if the :ioc argument (see 
  2823.                           below) is specified with a non-nil 
  2824.                           value.  :output supercedes :ioc. 
  2825.  
  2826.      :username            The user-name of sub-process.  Must be 
  2827.                           a string.  If not specfied, the current 
  2828.                           user-name is used.
  2829.  
  2830.      :list                If a string, the name of the file to be 
  2831.                           associated to @list is used.  If t, the
  2832.                           file currently associated to @list is used.
  2833.                           If nil, or if not specified, no list file is 
  2834.                           passed to the son.
  2835.  
  2836.      :data                If a string, the name of the file to be 
  2837.                           associated to @data.  If t, the file 
  2838.                           currently associated to @list is used.  
  2839.                           If nil, or if not specified, no list
  2840.                           file is passed to the son.
  2841.  
  2842.      :ioc                 If non-nil, current @input, @output, 
  2843.                           and @console files are passed to the 
  2844.                           son.  If not specified, these files are 
  2845.                           not passed unless specified by the 
  2846.                           :console, :input, or :output arguments.
  2847.  
  2848. Example:
  2849.  
  2850.      >(process ":cli.pr")
  2851.  
  2852.     AOS/VS CLI  Rev 03f.03.00.00       01-July-87        12:00:00
  2853.     )by
  2854.     AOS/VS CLI TERMINATING             01-July-87        12:00:00
  2855.     t
  2856.   
  2857.     >
  2858.  
  2859.  
  2860. termination-message                                    [Function]
  2861.  
  2862. This function is defined only in KCL/AOS.  termination-message retruns a
  2863. string consisting of the termination message of a son.  Used in connection
  2864. with the function process.
  2865.  
  2866. last-termination-message                               [Function]
  2867.  
  2868. This function is defined only in KCL/AOS.  last-termination-message flushes
  2869. all the messages currently spooled and returns the last termination
  2870. message.
  2871.  
  2872.  
  2873.  
  2874.  
  2875.                        Chapter 9. Macros
  2876.  
  2877.  
  2878.  
  2879. 9.1. System Macros
  2880.  
  2881. The KCL interpreter implements the following system macros as if they were
  2882. special forms.  That is, macro forms of the following macros are directly
  2883. evaluated without being macro-expanded.
  2884.  
  2885.     and       case      cond      decf      defmacro  defun
  2886.     do        do*       dolist    dotimes   incf      locally
  2887.     loop      multiple-value-bind           multiple-value-list
  2888.     multiple-value-setq           or        pop       prog
  2889.     prog*     prog1     prog2     psetq     push      return
  2890.     setf      unless    when
  2891.  
  2892. For these macro forms, the functions macro-function and special-form-p both
  2893. return non-nil values:  macro-function returns the macro expansion function
  2894. and special-form-p returns t.  Of course, functions such as macroexpand and
  2895. macroexpand-1 will successfully expand macro forms for these system macros.
  2896.  
  2897.  
  2898. 9.2. Defmacro Lambda-Lists
  2899.  
  2900. A defmacro lambda-list is a lambda-list-like construct that is used as the
  2901. third element in the defmacro form,
  2902.  
  2903.     (defmacro name defmacro-lambda-list {declaration | doc-string}* {form}* )
  2904.  
  2905. The description of defmacro lambda-lists in the Common Lisp Reference
  2906. Manual is quite ambiguous.  KCL employs the following syntax.
  2907.  
  2908. The complete syntax of a defmacro lambda-list is:
  2909.  
  2910. ( [ &whole var ]
  2911.   [ &environment var ]
  2912.   { pseudo-var }*
  2913.   [ &optional { var | ( pseudo-var [ initform [ pseudo-var ] ] ) }* ]
  2914.   {  [ { &rest | &body } pseudo-var ]
  2915.      [ &key { var | ( { var | ( keyword pseudo-var ) } [ initform 
  2916. [ pseudo-var ] ] ) }*
  2917.             [ &allow-other-keys ] ]
  2918.      [ &aux { var | ( pseudo-var [ initform ] ) }* ]
  2919.   |  . var }
  2920.  )
  2921.  
  2922. where pseudo-var is either a symbol or a list of the following form:
  2923.  
  2924. ( { pseudo-var }*
  2925.   [ &optional { var | ( pseudo-var [ initform [ pseudo-var ] ] ) }* ]
  2926.   {  [ { &rest | &body } pseudo-var ]
  2927.      [ &key { var | ( { var | ( keyword pseudo-var ) } [ initform 
  2928. [ pseudo-var ] ] ) }*
  2929.             [ &allow-other-keys ] ]
  2930.      [ &aux { var | ( pseudo-var [ initform ] ) }* ]
  2931.   |  . var }
  2932.  )
  2933.  
  2934. The defmacro lambda-list keyword &whole may appear only at the top-level,
  2935. first in the defmacro lambda-list.  It is not allowed within pseudo-var.
  2936. Use of the &whole keyword does not affect the processing of the rest of the
  2937. defmacro lambda-list:
  2938.  
  2939.     (defmacro foo (&whole w x y) ... )
  2940.  
  2941.  
  2942. and
  2943.  
  2944.     (defmacro foo (x y) ... )
  2945.  
  2946. both bind the variables x and y to the second and the third elements,
  2947. respectively, of macro forms of foo.
  2948.  
  2949.      The defmacro lambda-list keyword &environment may appear only at the
  2950. top-level, first in the defmacro lambda-list if &whole is not supplied, or
  2951. immediately after the variable that follows &whole, if &whole is supplied.
  2952. &environment is not allowed within pseudo-var.  Like &whole, use of
  2953. &environment does not affect the processing of the rest of the defmacro
  2954. lambda-list.  If an &environment parameter is supplied and if this
  2955. parameter is not used at all, then the KCL compiler will issue a warning.
  2956. To suppress the warning, just remove the parameter from the defmacro
  2957. lambda-list, or add an ignore declaration.
  2958.  
  2959.      The defmacro lambda-list keyword &body is completely equivalent to the
  2960. &rest keyword.  KCL takes no special action for &body parameters.
  2961.  
  2962.      Although useless, KCL allows supplied-p parameters to be destructured.
  2963. This is useless because supplied-p parameters can never be bound to a
  2964. non-empty list.  Our intention is to stick to the specification in the
  2965. Common Lisp Reference Manual as far as possible, even if it is silly to do
  2966. so.
  2967.  
  2968.      Like for ordinary lambda-lists, the interpreter detects invalid
  2969. arguments to macro expansion functions.  When a parameter is destructured,
  2970. the structure of the corresponding argument is also checked.  Such runtime
  2971. argument checking may or may not be embedded in compiled code, depending on
  2972. the environment when the code was generated.  If the code was generated
  2973. while the safety optimize level is zero (that is, while the value of
  2974. (proclamation '(optimize (safety 0))) is t), then the generated code does
  2975. not perform argument checking at all.  Otherwise, the compiled code does
  2976. check the validity of arguments.
  2977.  
  2978.  
  2979.  
  2980.  
  2981.                     Chapter 10. The C Language Interface
  2982.  
  2983.  
  2984. This chapter describes the facility of KCL to interface the C language and
  2985. KCL.  With this facility, the user can arrange his or her C-language
  2986. programs so that they can be invoked from KCL.  In addition, the user can
  2987. write Lisp function definitions in the C language to increase runtime
  2988. efficiency.
  2989.  
  2990.      The basic idea of interfacing the C language is this:  As mentioned in
  2991. Chapter 6, the KCL compiler, given a Lisp source file, creates an
  2992. intermediate C-language program file, called c-file, which is then compiled
  2993. by the C-language compiler to obtain the final fasl-file.  Usually, the
  2994. c-file consists of C-language function definitions.  The first C-language
  2995. function in the c-file is the "initializer", which is executed when the
  2996. fasl file is loaded, and the other C-language functions are the C versions
  2997. of the Lisp functions (including macro expansion functions) defined in the
  2998. source file.  By using the top-level macros Clines and defCfun described
  2999. below, the user can direct the compiler to insert his or her own C-language
  3000. function definitions and/or C-language preprocessor macros such as #define
  3001. and #include into the c-file.  In order that such C-language functions be
  3002. invoked from KCL, another top-level macro defentry is used.  This macro
  3003. defines a Lisp function whose body consists of the calling sequence to the
  3004. specified C-language function.
  3005.  
  3006.      The C-language function definitions are placed in the c-file in the
  3007. order of the corresponding Lisp functions defined in the source file.  That
  3008. is, the C code for the first Lisp function comes first, the C code for the
  3009. second Lisp function comes second, and so on.  If a Clines or defCfun macro
  3010. form appears between two Lisp function definitions in the source file, then
  3011. the C code specified by the macro is placed in between the C code for the
  3012. Lisp functions.
  3013.  
  3014.      We define some terminology here which is used throughout this Chapter.
  3015. A C-id is either a Lisp string consisting of a valid C-language identifier,
  3016. or a Lisp symbol whose print-name, with all its alphabetic characters
  3017. turned into lower case, is a valid C identifier.  Thus the symbol foo is
  3018. equivalent to the string "foo" when used as a C-id.  Similarly, a C-expr is
  3019. a string or a symbol that may be regarded as a C-language expression.  A
  3020. C-type is one of the Lisp symbols int, char, float, double, and object.
  3021. Each corresponds to a data type in the C language; object is the type of
  3022. Lisp object and other C-types are primitive data types in the C language.
  3023.  
  3024.  
  3025. Clines {string}*                                            [Macro]
  3026.  
  3027. When the KCL compiler encounters a macro form (Clines string1 ... stringn),
  3028. it simply outputs the strings into the c-file.  The arguments are not
  3029. evaluated and each argument must be a string.  Each string may consist of
  3030. any number of lines, and separate lines in the string are placed in
  3031. separate lines in the c-file.  In addition, each string opens a fresh line
  3032. in the c-file, i.e., the first character in the string is placed at the
  3033. first column of a line.  Therefore, C-language preprocessor commands such
  3034. as #define and #include will be recognized as such by the C compiler, if
  3035. the '#' sign appears as the first character of the string or as the first
  3036. character of a line within the string.
  3037.  
  3038.      In order to clearly distinguish C code from other parts of Lisp programs,
  3039. we, the implementors of KCL, make it our rule to start each C code line
  3040. with a percent sign '%'.  We define % as a read macro
  3041. which returns the rest of the line as a string.  For example,
  3042.  
  3043.         ;;; C version of TAK.
  3044.         (Clines
  3045.  
  3046.         %       int tak(x, y, z)
  3047.         %       int x, y, z;
  3048.         %       {       if (y >= x) return(z);
  3049.         %               else return(tak(tak(x-1, y, z),
  3050.         %                               tak(y-1, z, x),
  3051.         %                               tak(z-1, x, y)));
  3052.         %       }
  3053.  
  3054.         )
  3055.  
  3056. Of course, the user may instead enclose each C code line or the whole C
  3057. code with double quotes, but we recommend the use of the percent sign read
  3058. macro.  Since the percent sign read macro is not a standard read macro, the
  3059. users must define this read macro by themselves.  We use the following
  3060. definition.
  3061.  
  3062.         (set-macro-character
  3063.             #\%
  3064.             #'(lambda (stream char) (values (read-line stream)))))
  3065.  
  3066. Here, the lambda-expression returns the first value of read-line by using
  3067. values as a filter.
  3068.  
  3069.      When interpreted, a Clines macro form expands to nil.
  3070.  
  3071.  
  3072. defentry function parameter-list C-function         [Macro]
  3073.  
  3074. defentry defines a Lisp function whose body consists of the calling
  3075. sequence to a C-language function.  function is the name of the Lisp
  3076. function to be defined, and C-function specifies the C function to be
  3077. invoked.  C-function must be either a list (type C-id) or C-id, where type
  3078. and C-id are the type and the name of the C function.  type must be a
  3079. C-type or the symbol void which means that the C function returns no value.
  3080. (object C-id) may be abbreviated as C-id.  parameter-list is a list of
  3081. C-types for the parameters of the C function.  For example, the following
  3082. defentry form defines a Lisp function tak from which the C function tak
  3083. above is called.
  3084.  
  3085.         (defentry tak (int int int) (int tak))
  3086.  
  3087. The Lisp function tak defined by this defentry form requires three
  3088. arguments.  The arguments are converted to int values before they are
  3089. passed to the C function.  On return from the C function, the returned int
  3090. value is converted to a Lisp integer (actually a fixnum) and this fixnum
  3091. will be returned as the value of the Lisp function.  See below for type
  3092. conversion between Lisp and the C language.
  3093.  
  3094.      A defentry form is treated in the above way only when it appears as a
  3095. top-level form of a Lisp source file.  Otherwise, a defentry form expands
  3096. to nil.
  3097.  
  3098.  
  3099. defla name lambda-list {declaration | doc-string}* {form}*       [Macro]
  3100.  
  3101. When interpreted, defla is exactly the same as defun.  That is, (defla name
  3102. lambda-list . body) expands to (defun name lambda-list . body).  However,
  3103. defla forms are completely ignored by the compiler; no C-language code will
  3104. be generated for defla forms.  The primary use of defla is to define a Lisp
  3105. function in two ways within a single Lisp source file; one in the C
  3106. language and the other in Lisp.  defla is short for DEFine Lisp
  3107. Alternative.
  3108.  
  3109.      Suppose you have a Lisp source file whose contents are:
  3110.  
  3111.         ;;; C version of TAK.
  3112.         (Clines
  3113.  
  3114.         %       int tak(x, y, z)
  3115.         %       int x, y, z;
  3116.         %       {       if (y >= x) return(z);
  3117.         %               else return(tak(tak(x-1, y, z),
  3118.         %                               tak(y-1, z, x),
  3119.         %                               tak(z-1, x, y)));
  3120.         %       }
  3121.  
  3122.         )
  3123.  
  3124.         ;;;  TAK calls the C function tak defined above.
  3125.         (defentry tak (int int int) (int tak))
  3126.  
  3127.         ;;; The alternative Lisp definition of TAK.
  3128.         (defla tak (x y z)
  3129.          (if (>= y x)
  3130.          z
  3131.          (tak (tak (1- x) y z)
  3132.          (tak (1- y) z x)
  3133.          (tak (1- z) x y))))
  3134.  
  3135. When this file is loaded into KCL, the interpreter uses the Lisp version of
  3136. the tak definition.  Once this file has been compiled, and when the
  3137. generated fasl file is loaded into KCL, a function call to tak is actually
  3138. the call to the C version of tak.
  3139.  
  3140.  
  3141. defCfun header n {element}*                            [Macro]
  3142.  
  3143. defCfun defines a C-language function which calls Lisp functions and/or
  3144. which handles Lisp objects.  header is a string consisting of the C code
  3145. for
  3146.  
  3147.         the optional type-specifier of the C function,
  3148.         the function-declarator of the C function, and
  3149.         the type-decl-list of the parameters to the C function.
  3150.  
  3151. (For the C-language terminology, refer to The C Programming Language by
  3152. Brian W.  Kernighan and Dennis M. Ritchie.)  The rest of the C function
  3153. definition, i.e., the function-statement, is given by elements.  Each
  3154. element may be a string, in which case the string is treated in the same
  3155. way as the arguments to the Clines macro.  Or else, the element is a list
  3156. ((name arg1 ... argn) place1 ... placem).  The compiler translates this
  3157. list into a calling sequence to the Lisp function whose name is name.  As
  3158. will be mentioned later, name may be quote, but name may not be the name of
  3159. any other special form or a macro.  The args specify the arguments to the
  3160. function and the places specify where the values should go.  Thus the
  3161. list-formed element could be regarded as something like the Lisp form:
  3162.  
  3163.         (multiple-value-setq
  3164.             (place1 ... placem)
  3165.             (name arg1 ... argn)).
  3166.  
  3167. Each arg is a list (C-type C-expr), where C-expr is any C-language
  3168. expression of the  type C-type.  If type is object, then arg may be written
  3169. simply as C-expr.  Similarly, each place is a list (C-type C-expr), or it
  3170. may be abbreviated as C-expr if C-type is object.  The C-expr in this case
  3171. is any lvalue (in the terminology of the C language), i.e., it may be any
  3172. valid C-language code that can be written at the left side of an
  3173. assignment.
  3174.  
  3175.      The function call is performed as follows.  The args are evaluated,
  3176. and the values are sent to the specified Lisp function after type
  3177. conversion from C to Lisp.  On return from the called Lisp function, each
  3178. returned value is assigned to the corresponding place, i.e., the first
  3179. returned value goes to place1, the second to place2, and so on.  If there
  3180. are more places than the values returned, extra values of nil are assigned
  3181. to the remaining places.  If there are more values than places, the excess
  3182. values are simply discarded.  If necessary, Lisp-to-C type conversion may
  3183. take place before each returned value is assigned.
  3184.  
  3185.      If the Lisp function is called just for side-effects, then the
  3186. list-formed element may be abbreviated as a one-level list (name arg1 ...
  3187. argn).
  3188.  
  3189.      As a special case, if a list-formed element is of the form ((quote
  3190. value) place), the Lisp object value is assigned to place.  Here value may
  3191. be any Lisp object.
  3192.  
  3193.      The following defCfun form defines the C function silly which adds 100
  3194. to the value of the parameter x and prints the result in three different
  3195. ways.  The second argument to defCfun will be described later, and the user
  3196. may ignore it.
  3197.  
  3198.         (defCfun "silly(x) int x;" 0
  3199.         %       int y;
  3200.                 ((+ (int x) (int "100")) (int y))
  3201.         %       printf("\\n%d", y);
  3202.         %       y = x+100;
  3203.                 (print (int y))
  3204.                 (print (int "x+100"))
  3205.         )
  3206.  
  3207.      When a C function handles Lisp objects (i.e., data of type object),
  3208. the user should be careful enough so that the objects may not be
  3209. garbage-collected.  This is because the garbage collector of KCL does not
  3210. take care of Lisp objects used in the C function.  See the following C
  3211. function which is assumed to return a two-element list consisting of its
  3212. two arguments.
  3213.  
  3214.         (defCfun "object list2(x,y) object x,y;" 0
  3215.         %       object z;
  3216.                 ('nil z)
  3217.                 ((cons y z) z)
  3218.                 ((cons x z) z)
  3219.         %       return(z);
  3220.         )
  3221.  
  3222. When invoked, list2 first sets nil to the variable z, conses y to z, and
  3223. then conses x.  Each time cons is called, a new cons cell is allocated and
  3224. the pointer to this cell is stored in z.  However, there is no way to
  3225. inform the garbage collector that the cells are referenced from the C
  3226. variable z.  Suppose that the cons cell allocated by the first cons is the
  3227. last cons cell available at that time.  Then, during execution of the
  3228. second call to cons, the garbage collector begins to run and,
  3229. unfortunately, the cons cell in z will be destroyed so that the cell can be
  3230. recycled for further use.
  3231.  
  3232.      To prevent a Lisp object from being unexpectedly garbage 
  3233. collected, the user must save the object in some place that is 
  3234. recognized by the garbage collector.  The second parameter n 
  3235. to defCfun is used to reserve n such places for each call to the
  3236. C function.  In the body of the C function, these reserved places 
  3237. are referenced as vs[0], ..., vs[n-1].  The function list2 above, 
  3238. therefore, should be revised as follows.
  3239.  
  3240.         (defCfun "object list2(x,y) object x,y;" 1
  3241.                 ('nil "vs[0]")
  3242.                 ((cons y "vs[0]") "vs[0]")
  3243.                 ((cons x "vs[0]") "vs[0]")
  3244.         %       Creturn(vs[0]);
  3245.         )
  3246.  
  3247. Notice that return is replaced by Creturn.  Creturn is similar to return
  3248. except that Creturn releases the reserved places on return from the
  3249. function.  In the C code within a defCfun form, write "Creturn(value);"
  3250. instead of "return(value);", and write "Cexit;" instead of "return;".
  3251.  
  3252.      Again, a defCfun form has the above meaning only when it appears as a
  3253. top-level form in a Lisp source file.  Otherwise, the form expands to nil.
  3254.  
  3255.      KCL converts a Lisp object into a C-language data by using the Common
  3256. Lisp function coerce: For the C-type int (or char), the object is first
  3257. coerced to a Lisp integer and the least significant 32-bit (or 8-bit) field
  3258. is used as the C int (or char).  For the C-type float (or double), the
  3259. object is coerced to a short-float (or a long-float) and this value is used
  3260. as the C float (or double).  Conversion from a C data into a Lisp object is
  3261. obvious: C char, int, float, and double become the equivalent Lisp
  3262. character, fixnum, short-float, and long-float, respectively.
  3263.  
  3264.      Here we list the complete syntax of Clines, defentry, 
  3265. and defCfun macro forms.
  3266.  
  3267.         Clines-form:
  3268.                 (Clines { string }* )
  3269.  
  3270.         defentry-form:
  3271.                 (defentry function-symbol
  3272.                         ( { C-type }* )
  3273.                  C-function-name | ( { C-type | void } C-function-name ) } )
  3274.  
  3275.         defCfun-form:
  3276.                 (defCfun string  non-negative-integer
  3277.                         { string
  3278.                           | (function-symbol { value }* )
  3279.                           | ((function-symbol { value }* ) { place }* ) } )
  3280.  
  3281.         value:
  3282.         place:
  3283.                 { C-expr | (C-type C-expr) }
  3284.  
  3285.         C-function-name:
  3286.         C-expr:
  3287.                 { string | symbol }
  3288.  
  3289.         C-type:
  3290.                 { object | int | char | float | double }
  3291.  
  3292.  
  3293.  
  3294.  
  3295.                               Chapter 11. The Editor
  3296.  
  3297.  
  3298.  
  3299. KCL/AOS is equipped with a screen editor FeCl2 (Full-screen Editor as a
  3300. Common Lisp TOOl).  FeCl2 is an EMACS-like editor with facilities for Lisp
  3301. coding.  FeCl2 is invoked from KCL by the function ed and the result of
  3302. editing can be passed to KCL directly.  For the details of FeCl2 refer to
  3303. The FeCl2 Editor Reference Manual.
  3304.  
  3305. ed &optional filename                                    [Function]
  3306.  
  3307. ed invokes FeCl2 and sets the edit file of FeCl2 to filename.  If the
  3308. filetype of the file is not explicitly specified, then the filename is
  3309. first merged into #".lsp".
  3310.  
  3311.  
  3312. The FeCl2 editor is not supported by other versions of KCL.  The function
  3313. ed of KCL/VAX, KCL/SUN, and KCL/UST calls the vi editor.  If you hate vi,
  3314. define your own ed function using the function system described in Chapter
  3315. 8.
  3316.  
  3317.  
  3318.  
  3319.  
  3320.  
  3321.                            Appendix A. KCL Summary
  3322.  
  3323.  
  3324. The following table lists all symbols defined in KCL.  Each line has the
  3325. following form.
  3326.  
  3327.        symbol   [kind]   remark
  3328.  
  3329. where kind is Function, Macro, Special (i.e., Special form name), Variable,
  3330. Constant, Symbol, or Keyword.  In the table, some symbols are labeled both
  3331. as a macro and a special form name.  This means that, although these
  3332. symbols are defined to be a macro name in the Common Lisp Reference Manual,
  3333. KCL treats them as if they were special forms (see Section 9.1).  
  3334.  
  3335. *                               [Function]
  3336. *                               [Variable]
  3337. **                              [Variable]
  3338. ***                             [Variable]
  3339. +                               [Function]
  3340. +                               [Variable]
  3341. ++                              [Variable]
  3342. +++                             [Variable]
  3343. -                               [Function]
  3344. -                               [Variable]
  3345. /                               [Function]
  3346. /                               [Variable]
  3347. //                              [Variable]
  3348. ///                             [Variable]
  3349. /=                              [Function]
  3350. 1+                              [Function]
  3351. 1-                              [Function]
  3352. <                               [Function]
  3353. <=                              [Function]
  3354. =                               [Function]
  3355. >                               [Function]
  3356. >=                              [Function]
  3357. :abort                          [Keyword]
  3358. abs                             [Function]
  3359. acons                           [Function]
  3360. acos                            [Function]
  3361. acosh                           [Function]
  3362. adjoin                          [Function]
  3363. adjust-array                    [Function]
  3364. :adjustable                     [Keyword]
  3365. adjustable-array-p              [Function]
  3366. allocate                        [Function] Added.
  3367. allocate-contiguous-pages       [Function] Added.
  3368. allocated-contiguous-pages      [Function] Added.
  3369. allocated-pages                 [Function] Added.
  3370. allocated-relocatable-pages     [Function] Added.
  3371. allocate-relocatable-pages      [Function] Added.
  3372. alpha-char-p                    [Function]
  3373. alphanumericp                   [Function]
  3374. and                             [Special, Macro]
  3375. append                          [Function]
  3376. :append                         [Keyword]
  3377. apply                           [Function]
  3378. applyhook                       [Function]
  3379. *applyhook*                     [Variable]
  3380. apropos                         [Function]
  3381. apropos-list                    [Function]
  3382. aref                            [Function]
  3383. :array                          [Keyword]
  3384. array-dimension                 [Function]
  3385. array-dimension-limit           [Constant]
  3386. array-dimensions                [Function]
  3387. array-element-type              [Function]
  3388. array-has-fill-pointer-p        [Function]
  3389. array-in-bounds-p               [Function]
  3390. array-rank                      [Function]
  3391. array-rank-limit                [Constant]
  3392. array-row-major-index           [Function]
  3393. array-total-size                [Function]
  3394. array-total-size-limit          [Constant]
  3395. arrayp                          [Function]
  3396. ash                             [Function]
  3397. asin                            [Function]
  3398. asinh                           [Function]
  3399. assert                          [Macro]
  3400. assoc                           [Function]
  3401. assoc-if                        [Function]
  3402. assoc-if-not                    [Function]
  3403. atan                            [Function]
  3404. atanh                           [Function]
  3405. atom                            [Function]
  3406. :b                              [Keyword] Abbreviate Break Loop Command.
  3407. :backtrace                      [Keyword] Break Loop Command.
  3408. :base                           [Keyword]
  3409. bit                             [Function]
  3410. bit-and                         [Function]
  3411. bit-andc1                       [Function]
  3412. bit-andc2                       [Function]
  3413. bit-eqv                         [Function]
  3414. bit-ior                         [Function]
  3415. bit-nand                        [Function]
  3416. bit-nor                         [Function]
  3417. bit-not                         [Function]
  3418. bit-orc1                        [Function]
  3419. bit-orc2                        [Function]
  3420. bit-vector-p                    [Function]
  3421. bit-xor                         [Function]
  3422. block                           [Special]
  3423. :block                          [Keyword] Added.
  3424. :blocks                         [Keyword] Break Loop Command.
  3425. boole                           [Function]
  3426. boole-1                         [Constant]
  3427. boole-2                         [Constant]
  3428. boole-and                       [Constant]
  3429. boole-andc1                     [Constant]
  3430. boole-andc2                     [Constant]
  3431. boole-c1                        [Constant]
  3432. boole-c2                        [Constant]
  3433. boole-clr                       [Constant]
  3434. boole-eqv                       [Constant]
  3435. boole-ior                       [Constant]
  3436. boole-nand                      [Constant]
  3437. boole-nor                       [Constant]
  3438. boole-orc1                      [Constant]
  3439. boole-orc2                      [Constant]
  3440. boole-set                       [Constant]
  3441. boole-xor                       [Constant]
  3442. both-case-p                     [Function]
  3443. boundp                          [Function]
  3444. break                           [Function]
  3445. *break-on-warnings*             [Variable]
  3446. *break-enable*                  [Variable] Added.
  3447. butlast                         [Function]
  3448. by                              [Function] Added.
  3449. bye                             [Function] Added.
  3450. byte                            [Function]
  3451. byte-position                   [Function]
  3452. byte-size                       [Function]
  3453. :c                              [Keyword] Abbreviated Break Loop Command.
  3454. caaaar                          [Function]
  3455. caaadr                          [Function]
  3456. caaar                           [Function]
  3457. caadar                          [Function]
  3458. caaddr                          [Function]
  3459. caadr                           [Function]
  3460. caar                            [Function]
  3461. cadaar                          [Function]
  3462. cadadr                          [Function]
  3463. cadar                           [Function]
  3464. caddar                          [Function]
  3465. cadddr                          [Function]
  3466. caddr                           [Function]
  3467. cadr                            [Function]
  3468. call-arguments-limit            [Constant]
  3469. car                             [Function]
  3470. :case                           [Keyword]
  3471. case                            [Special, Macro]
  3472. catch                           [Special]
  3473. ccase                           [Macro]
  3474. cdaaar                          [Function]
  3475. cdaadr                          [Function]
  3476. cdaar                           [Function]
  3477. cdadar                          [Function]
  3478. cdaddr                          [Function]
  3479. cdadr                           [Function]
  3480. cdar                            [Function]
  3481. cddaar                          [Function]
  3482. cddadr                          [Function]
  3483. cddar                           [Function]
  3484. cdddar                          [Function]
  3485. cddddr                          [Function]
  3486. cdddr                           [Function]
  3487. cddr                            [Function]
  3488. cdr                             [Function]
  3489. ceiling                         [Function]
  3490. cerror                          [Function]
  3491. :c-file                         [Keyword] Added.
  3492. char                            [Function]
  3493. char-bit                        [Function]
  3494. char-bits                       [Function]
  3495. char-bits-limit                 [Constant]
  3496. char-code                       [Function]
  3497. char-code-limit                 [Constant]
  3498. char-control-bit                [Constant]
  3499. char-downcase                   [Function]
  3500. char-equal                      [Function]
  3501. char-font                       [Function]
  3502. char-font-limit                 [Constant]
  3503. char-greaterp                   [Function]
  3504. char-hyper-bit                  [Constant]
  3505. char-int                        [Function]
  3506. char-lessp                      [Function]
  3507. char-meta-bit                   [Constant]
  3508. char-name                       [Function]
  3509. char-not-equal                  [Function]
  3510. char-not-greaterp               [Function]
  3511. char-not-lessp                  [Function]
  3512. char-super-bit                  [Constant]
  3513. char-upcase                     [Function]
  3514. char/=                          [Function]
  3515. char<                           [Function]
  3516. char<=                          [Function]
  3517. char=                           [Function]
  3518. char>                           [Function]
  3519. char>=                          [Function]
  3520. character                       [Function]
  3521. characterp                      [Function]
  3522. check-type                      [Macro]
  3523. :circle                         [Keyword]
  3524. cis                             [Function]
  3525. clear-input                     [Function] Different.
  3526. clear-output                    [Function] Different.
  3527. clines                          [Macro] Added.
  3528. close                           [Function] Different.
  3529. clrhash                         [Function]
  3530. code-char                       [Function]
  3531. coerce                          [Function]
  3532. commonp                         [Function]
  3533. compilation-speed               [Symbol] Optimize Quality.
  3534. compile                         [Function]
  3535. compile-file                    [Function]
  3536. compiled-function-p             [Function]
  3537. compiler-let                    [Special]
  3538. complex                         [Function]
  3539. complexp                        [Function]
  3540. :conc-name                      [Keyword]
  3541. concatenate                     [Function]
  3542. cond                            [Special, Macro]
  3543. conjugate                       [Function]
  3544. cons                            [Function]
  3545. :console                        [Keyword] Added.
  3546. consp                           [Function]
  3547. constantp                       [Function]
  3548. :constructor                    [Keyword]
  3549. :copier                         [Keyword]
  3550. copy-alist                      [Function]
  3551. copy-list                       [Function]
  3552. copy-readtable                  [Function]
  3553. copy-seq                        [Function]
  3554. copy-symbol                     [Function]
  3555. copy-tree                       [Function]
  3556. cos                             [Function]
  3557. cosh                            [Function]
  3558. count                           [Function]
  3559. :count                          [Keyword]
  3560. count-if                        [Function]
  3561. count-if-not                    [Function]
  3562. :create                         [Keyword]
  3563. ctypecase                       [Macro]
  3564. :current                        [Keyword] Break Loop Command.
  3565. :data                           [Keyword] Added.
  3566. :data-file                      [Keyword] Added.
  3567. :debug                          [Keyword] Added.
  3568. *debug-io*                      [Variable]
  3569. decf                            [Special, Macro]
  3570. declaration                     [Symbol] Declaration Specifier.
  3571. declare                         [Special]
  3572. decode-float                    [Function]
  3573. decode-universal-time           [Function]
  3574. :default                        [Keyword]
  3575. *default-pathname-defaults*     [Variable]
  3576. :defaults                       [Keyword]
  3577. defautoload                     [Macro] Added.
  3578. defcfun                         [Macro] Added.
  3579. defconstant                     [Macro]
  3580. defentry                        [Macro] Added.
  3581. define-modify-macro             [Macro]
  3582. define-setf-method              [Macro]
  3583. defla                           [Macro] Added.
  3584. defmacro                        [Special, Macro]
  3585. defparameter                    [Macro]
  3586. defsetf                         [Macro]
  3587. defstruct                       [Macro]
  3588. deftype                         [Macro]
  3589. defun                           [Special, Macro]
  3590. defvar                          [Macro]
  3591. delete                          [Function]
  3592. delete-duplicates               [Function]
  3593. delete-file                     [Function]
  3594. delete-if                       [Function]
  3595. delete-if-not                   [Function]
  3596. denominator                     [Function]
  3597. deposit-field                   [Function]
  3598. describe                        [Function]
  3599. :device                         [Keyword]
  3600. digit-char                      [Function]
  3601. digit-char-p                    [Function]
  3602. :dir                            [Keyword] Added.
  3603. :direction                      [Keyword]
  3604. directory                       [Function]
  3605. :directory                      [Keyword]
  3606. directory-namestring            [Function]
  3607. disassemble                     [Function] Different.
  3608. :displaced-index-offset         [Keyword]
  3609. :displaced-to                   [Keyword]
  3610. do                              [Special, Macro]
  3611. do*                             [Special, Macro]
  3612. do-all-symbols                  [Macro]
  3613. do-external-symbols             [Macro]
  3614. do-symbols                      [Macro]
  3615. documentation                   [Function]
  3616. dolist                          [Special, Macro]
  3617. dotimes                         [Special, Macro]
  3618. double-float-epsilon            [Constant]
  3619. double-float-negative-epsilon   [Constant]
  3620. dpb                             [Function]
  3621. dribble                         [Function]
  3622. ecase                           [Macro]
  3623. ed                              [Function] Different.
  3624. eighth                          [Function]
  3625. :element-type                   [Keyword]
  3626. elt                             [Function]
  3627. encode-universal-time           [Function]
  3628. :end                            [Keyword]
  3629. :end1                           [Keyword]
  3630. :end2                           [Keyword]
  3631. endp                            [Function]
  3632. enough-namestring               [Function]
  3633. &environment                    [Symbol] Defmacro-lambda Keyword.
  3634. eq                              [Function]
  3635. eql                             [Function]
  3636. equal                           [Function]
  3637. equalp                          [Function]
  3638. error                           [Function]
  3639. :error                          [Keyword]
  3640. *error-output*                  [Variable]
  3641. :escape                         [Keyword]
  3642. etypecase                       [Macro]
  3643. eval                            [Function]
  3644. evalhook                        [Function]
  3645. *evalhook*                      [Variable]
  3646. eval-when                       [Macro]
  3647. *eval-when-compile*             [Variable] Added.
  3648. evenp                           [Function]
  3649. every                           [Function]
  3650. exp                             [Function]
  3651. export                          [Function]
  3652. expt                            [Function]
  3653. :external                       [Keyword]
  3654. :fasl-file                      [Keyword] Added.
  3655. fboundp                         [Function]
  3656. fceiling                        [Function]
  3657. *features*                      [Variable]
  3658. ffloor                          [Function]
  3659. fifth                           [Function]
  3660. file-author                     [Function]
  3661. file-length                     [Function]
  3662. file-namestring                 [Function]
  3663. file-position                   [Function]
  3664. file-write-date                 [Function]
  3665. fill                            [Function]
  3666. fill-pointer                    [Function]
  3667. :fill-pointer                   [Keyword]
  3668. find                            [Function]
  3669. find-all-symbols                [Function]
  3670. find-if                         [Function]
  3671. find-if-not                     [Function]
  3672. find-package                    [Function]
  3673. find-symbol                     [Function]
  3674. finish-output                   [Function]
  3675. first                           [Function]
  3676. flet                            [Special]
  3677. float                           [Function]
  3678. float-digits                    [Function]
  3679. float-precision                 [Function]
  3680. float-radix                     [Function]
  3681. float-sign                      [Function]
  3682. floatp                          [Function]
  3683. floor                           [Function]
  3684. fmakunbound                     [Function]
  3685. force-output                    [Function]
  3686. format                          [Function]
  3687. fourth                          [Function]
  3688. fresh-line                      [Function]
  3689. :from-end                       [Keyword]
  3690. fround                          [Function]
  3691. ftruncate                       [Function]
  3692. ftype                           [Symbol] Declaration Specifier.
  3693. funcall                         [Function]
  3694. function                        [Special] Also Declaration Specifier.
  3695. functionp                       [Function]
  3696. :functions                      [Keyword] Break Loop Command.
  3697. gbc                             [Function] Added.
  3698. gcd                             [Function]
  3699. gensym                          [Function]
  3700. :gensym                         [Keyword]
  3701. gentemp                         [Function]
  3702. get                             [Function]
  3703. get-decoded-time                [Function]
  3704. get-dispatch-macro-character    [Function]
  3705. get-internal-real-time          [Function]
  3706. get-internal-run-time           [Function]
  3707. get-macro-character             [Function]
  3708. get-output-stream-string        [Function]
  3709. get-properties                  [Function]
  3710. get-setf-method                 [Function]
  3711. get-setf-method-multiple-value  [Function]
  3712. get-universal-time              [Function]
  3713. getf                            [Function]
  3714. gethash                         [Function]
  3715. go                              [Special]
  3716. graphic-char-p                  [Function]
  3717. hash-table-count                [Function]
  3718. hash-table-p                    [Function]
  3719. :h                              [Keyword] Abbreviated Break Loop Command.
  3720. :help                           [Keyword] Break Loop Command.
  3721. :h-file                         [Keyword] Added.
  3722. :hide                           [Keyword] Break Loop Command.
  3723. :hide-package                   [Keyword] Break Loop Command.
  3724. :host                           [Keyword]
  3725. host-namestring                 [Function]
  3726. identity                        [Function]
  3727. if                              [Special]
  3728. :if-does-not-exist              [Keyword]
  3729. :if-exists                      [Keyword]
  3730. ignore                          [Symbol] Declaration Specifier.
  3731. *ignore-maximum-pages*          [Variable] Added.
  3732. imagpart                        [Function]
  3733. import                          [Function]
  3734. in-package                      [Function]
  3735. incf                            [Special, Macro]
  3736. :include                        [Keyword]
  3737. :index                          [Keyword]
  3738. :inherited                      [Keyword]
  3739. :initial-contents               [Keyword]
  3740. :initial-element                [Keyword]
  3741. :initial-offset                 [Keyword]
  3742. :initial-value                  [Keyword]
  3743. inline                          [Symbol] Declaration Specifier.
  3744. :input                          [Keyword]
  3745. input-stream-p                  [Function]
  3746. inspect                         [Function]
  3747. int-char                        [Function]
  3748. integer-decode-float            [Function]
  3749. integer-length                  [Function]
  3750. integerp                        [Function]
  3751. intern                          [Function]
  3752. :intern                         [Keyword]
  3753. internal-time-units-per-second  [Constant]
  3754. intersection                    [Function]
  3755. :io                             [Keyword]
  3756. :ioc                            [Keyword] Added.
  3757. isqrt                           [Function]
  3758. :junk-allowed                   [Keyword]
  3759. :key                            [Keyword]
  3760. keywordp                        [Function]
  3761. :l                              [Keyword] Abbreviated Break Loop Command.
  3762. labels                          [Special]
  3763. lambda-list-keywords            [Constant]
  3764. lambda-parameters-limit         [Constant]
  3765. last                            [Function]
  3766. last-termination-message        [Function] Added.
  3767. lcm                             [Function]
  3768. ldb                             [Function]
  3769. ldb-test                        [Function]
  3770. ldiff                           [Function]
  3771. least-negative-double-float     [Constant]
  3772. least-negative-long-float       [Constant]
  3773. least-negative-short-float      [Constant]
  3774. least-negative-single-float     [Constant]
  3775. least-positive-double-float     [Constant]
  3776. least-positive-long-float       [Constant]
  3777. least-positive-short-float      [Constant]
  3778. least-positive-single-float     [Constant]
  3779. length                          [Function]
  3780. :length                         [Keyword]
  3781. let                             [Special]
  3782. let*                            [Special]
  3783. :level                          [Keyword]
  3784. lisp-implementation-type        [Function]
  3785. lisp-implementation-version     [Function]
  3786. list                            [Function]
  3787. :list                           [Keyword] Added.
  3788. list*                           [Function]
  3789. list-all-packages               [Function]
  3790. list-length                     [Function]
  3791. listen                          [Function] Different.
  3792. listp                           [Function]
  3793. load                            [Function]
  3794. *load-verbose*                  [Variable]
  3795. :local                          [Keyword] Break Loop Command.
  3796. locally                         [Special, Macro]
  3797. log                             [Function]
  3798. logand                          [Function]
  3799. logandc1                        [Function]
  3800. logandc2                        [Function]
  3801. logbitp                         [Function]
  3802. logcount                        [Function]
  3803. logeqv                          [Function]
  3804. logior                          [Function]
  3805. lognand                         [Function]
  3806. lognor                          [Function]
  3807. lognot                          [Function]
  3808. logorc1                         [Function]
  3809. logorc2                         [Function]
  3810. logtest                         [Function]
  3811. logxor                          [Function]
  3812. long-float-epsilon              [Constant]
  3813. long-float-negative-epsilon     [Constant]
  3814. long-site-name                  [Function]
  3815. loop                            [Special, Macro]
  3816. lower-case-p                    [Function]
  3817. machine-instance                [Function]
  3818. machine-type                    [Function]
  3819. machine-version                 [Function]
  3820. macro-function                  [Function]
  3821. macroexpand                     [Function]
  3822. macroexpand-1                   [Function]
  3823. *macroexpand-hook*              [Variable]
  3824. macrolet                        [Special]
  3825. make-array                      [Function]
  3826. make-broadcast-stream           [Function]
  3827. make-char                       [Function]
  3828. make-concatenated-stream        [Function]
  3829. make-dispatch-macro-character   [Function]
  3830. make-echo-stream                [Function]
  3831. make-hash-table                 [Function]
  3832. make-list                       [Function]
  3833. make-package                    [Function]
  3834. make-pathname                   [Function]
  3835. make-random-state               [Function]
  3836. make-sequence                   [Function]
  3837. make-string                     [Function]
  3838. make-string-input-stream        [Function]
  3839. make-string-output-stream       [Function]
  3840. make-symbol                     [Function]
  3841. make-synonym-stream             [Function]
  3842. make-two-way-stream             [Function]
  3843. makunbound                      [Function]
  3844. map                             [Function]
  3845. mapc                            [Function]
  3846. mapcan                          [Function]
  3847. mapcar                          [Function]
  3848. mapcon                          [Function]
  3849. maphash                         [Function]
  3850. mapl                            [Function]
  3851. maplist                         [Function]
  3852. mask-field                      [Function]
  3853. max                             [Function]
  3854. maximum-allocatable-pages       [Function] Added.
  3855. maximum-contiguous-pages        [Function] Added.
  3856. member                          [Function]
  3857. member-if                       [Function]
  3858. member-if-not                   [Function]
  3859. merge                           [Function]
  3860. merge-pathnames                 [Function]
  3861. min                             [Function]
  3862. minusp                          [Function]
  3863. mismatch                        [Function]
  3864. mod                             [Function]
  3865. *modules*                       [Variable]
  3866. most-negative-double-float      [Constant]
  3867. most-negative-fixnum            [Constant]
  3868. most-negative-long-float        [Constant]
  3869. most-negative-short-float       [Constant]
  3870. most-negative-single-float      [Constant]
  3871. most-positive-double-float      [Constant]
  3872. most-positive-fixnum            [Constant]
  3873. most-positive-long-float        [Constant]
  3874. most-positive-short-float       [Constant]
  3875. most-positive-single-float      [Constant]
  3876. multiple-value-bind             [Special, Macro]
  3877. multiple-value-call             [Special]
  3878. multiple-value-list             [Special, Macro]
  3879. multiple-value-prog1            [Special]
  3880. multiple-value-setq             [Special, Macro]
  3881. multiple-values-limit           [Constant]
  3882. :n                              [Keyword] Abbreviated Break Loop Command.
  3883. :name                           [Keyword]
  3884. name-char                       [Function]
  3885. :named                          [Keyword]
  3886. namestring                      [Function]
  3887. nbutlast                        [Function]
  3888. nconc                           [Function]
  3889. :new-version                    [Keyword]
  3890. :next                           [Keyword] Break Loop Command.
  3891. nil                             [Constant]
  3892. nintersection                   [Function]
  3893. ninth                           [Function]
  3894. not                             [Function]
  3895. notany                          [Function]
  3896. notevery                        [Function]
  3897. notinline                       [Symbol] Declaration Specifier.
  3898. nreconc                         [Function]
  3899. nreverse                        [Function]
  3900. nset-difference                 [Function]
  3901. nset-exclusive-or               [Function]
  3902. nstring-capitalize              [Function]
  3903. nstring-downcase                [Function]
  3904. nstring-upcase                  [Function]
  3905. nsublis                         [Function]
  3906. nsubst                          [Function]
  3907. nsubst-if                       [Function]
  3908. nsubst-if-not                   [Function]
  3909. nsubstitute                     [Function]
  3910. nsubstitute-if                  [Function]
  3911. nsubstitute-if-not              [Function]
  3912. nth                             [Function]
  3913. nthcdr                          [Function]
  3914. null                            [Function]
  3915. numberp                         [Function]
  3916. numerator                       [Function]
  3917. nunion                          [Function]
  3918. :ob-file                        [Keyword] Added.
  3919. object                          [Symbol] Declaration Specifier.  Added.
  3920. oddp                            [Function]
  3921. :o-file                         [Keyword] Added.
  3922. open                            [Function] Different.
  3923. optimize                        [Symbol] Declaration Specifier.
  3924. or                              [Special, Macro]
  3925. :output                         [Keyword]
  3926. :output-file                    [Keyword]
  3927. output-stream-p                 [Function]
  3928. :overwrite                      [Keyword]
  3929. *package*                       [Variable]
  3930. package-name                    [Function]
  3931. package-nicknames               [Function]
  3932. package-shadowing-symbols       [Function]
  3933. package-use-list                [Function]
  3934. package-used-by-list            [Function]
  3935. packagep                        [Function]
  3936. pairlis                         [Function]
  3937. :parent                         [Keyword] Added.
  3938. parse-integer                   [Function]
  3939. parse-namestring                [Function]
  3940. pathname                        [Function]
  3941. pathname-device                 [Function]
  3942. pathname-directory              [Function]
  3943. pathname-host                   [Function]
  3944. pathname-name                   [Function]
  3945. pathname-type                   [Function]
  3946. pathname-version                [Function]
  3947. pathnamep                       [Function]
  3948. peek-char                       [Function]
  3949. phase                           [Function]
  3950. pi                              [Constant]
  3951. plusp                           [Function]
  3952. pop                             [Macro]
  3953. position                        [Function]
  3954. position-if                     [Function]
  3955. position-if-not                 [Function]
  3956. pprint                          [Function]
  3957. :p                              [Keyword] Abbreviate Break Loop Command.
  3958. :predicate                      [Keyword]
  3959. :preserve-whitespace            [Keyword]
  3960. :pretty                         [Keyword]
  3961. :previous                       [Keyword] Break Loop Command.
  3962. prin1                           [Function]
  3963. prin1-to-string                 [Function]
  3964. princ                           [Function]
  3965. princ-to-string                 [Function]
  3966. print                           [Function]
  3967. :print                          [Keyword]
  3968. *print-array*                   [Variable]
  3969. *print-base*                    [Variable]
  3970. *print-case*                    [Variable]
  3971. *print-circle*                  [Variable]
  3972. *print-escape*                  [Variable]
  3973. :print-function                 [Keyword]
  3974. *print-gensym*                  [Variable]
  3975. *print-length*                  [Variable]
  3976. *print-level*                   [Variable]
  3977. *print-pretty*                  [Variable]
  3978. *print-radix*                   [Variable]
  3979. :probe                          [Keyword]
  3980. probe-file                      [Function]
  3981. process                         [Function] Added.
  3982. proclaim                        [Function]
  3983. proclamation                    [Function] Added.
  3984. prog                            [Special, Macro]
  3985. prog*                           [Special, Macro]
  3986. prog1                           [Special, Macro]
  3987. prog2                           [Special, Macro]
  3988. progn                           [Special]
  3989. progv                           [Special]
  3990. provide                         [Function]
  3991. psetf                           [Macro]
  3992. psetq                           [Special, Macro]
  3993. push                            [Special, Macro]
  3994. pushnew                         [Macro]
  3995. :q                              [Keyword] Abbreviated Break Loop Command.
  3996. *query-io*                      [Variable]
  3997. :quit                           [Keyword] Break Loop Command.
  3998. quote                           [Special]
  3999. :r                              [Keyword] Abbreviated Break Loop Command.
  4000. :radix                          [Keyword]
  4001. random                          [Function]
  4002. *random-state*                  [Variable]
  4003. random-state-p                  [Function]
  4004. rassoc                          [Function]
  4005. rassoc-if                       [Function]
  4006. rassoc-if-not                   [Function]
  4007. rational                        [Function]
  4008. rationalize                     [Function]
  4009. rationalp                       [Function]
  4010. read                            [Function]
  4011. *read-base*                     [Variable]
  4012. read-byte                       [Function] Different.
  4013. read-char                       [Function]
  4014. read-char-no-hang               [Function] Different.
  4015. *read-default-float-format*     [Variable]
  4016. read-delimited-list             [Function]
  4017. read-from-string                [Function]
  4018. read-line                       [Function]
  4019. :read-only                      [Keyword]
  4020. read-preserving-whitespace      [Function]
  4021. *read-suppress*                 [Variable]
  4022. *readtable*                     [Variable]
  4023. readtablep                      [Function]
  4024. realpart                        [Function]
  4025. reduce                          [Function]
  4026. :rehash-size                    [Keyword]
  4027. :rehash-threshold               [Keyword]
  4028. rem                             [Function]
  4029. remf                            [Macro]
  4030. remhash                         [Function]
  4031. remove                          [Function]
  4032. remove-duplicates               [Function]
  4033. remove-if                       [Function]
  4034. remove-if-not                   [Function]
  4035. remprop                         [Function]
  4036. :rename                         [Keyword]
  4037. :rename-and-delete              [Keyword]
  4038. rename-file                     [Function]
  4039. rename-package                  [Function]
  4040. replace                         [Function]
  4041. require                         [Function]
  4042. :resume                         [Keyword] Break Loop Command.
  4043. rest                            [Function]
  4044. return                          [Special, Macro]
  4045. return-from                     [Special]
  4046. revappend                       [Function]
  4047. reverse                         [Function]
  4048. room                            [Function]
  4049. :root                           [Function] Added.
  4050. rotatef                         [Macro]
  4051. round                           [Function]
  4052. rplaca                          [Function]
  4053. rplacd                          [Function]
  4054. safety                          [Symbol] Optimize Quality.
  4055. save                            [Function] Added.
  4056. sbit                            [Function]
  4057. scale-float                     [Function]
  4058. schar                           [Function]
  4059. search                          [Function]
  4060. second                          [Function]
  4061. set                             [Function]
  4062. set-char-bit                    [Function]
  4063. set-difference                  [Function]
  4064. set-dispatch-macro-character    [Function]
  4065. set-exclusive-or                [Function]
  4066. set-macro-character             [Function]
  4067. set-syntax-from-char            [Function]
  4068. setf                            [Special, Macro]
  4069. setq                            [Special]
  4070. seventh                         [Function]
  4071. shadow                          [Function]
  4072. shadowing-import                [Function]
  4073. shiftf                          [Macro]
  4074. short-float-epsilon             [Constant]
  4075. short-float-negative-epsilon    [Constant]
  4076. short-site-name                 [Function]
  4077. signum                          [Function]
  4078. simple-bit-vector-p             [Function]
  4079. simple-string-p                 [Function]
  4080. simple-vector-p                 [Function]
  4081. sin                             [Function]
  4082. single-float-epsilon            [Constant]
  4083. single-float-negative-epsilon   [Constant]
  4084. sinh                            [Function]
  4085. sixth                           [Function]
  4086. :size                           [Keyword]
  4087. sleep                           [Function]
  4088. software-type                   [Function]
  4089. software-version                [Function]
  4090. some                            [Function]
  4091. sort                            [Function]
  4092. space                           [Symbol] Optimize Quality.
  4093. special                         [Symbol] Declaration Specifier.
  4094. special-form-p                  [Function]
  4095. speed                           [Symbol] Optimize Quality.
  4096. sqrt                            [Function]
  4097. stable-sort                     [Function]
  4098. standard-char-p                 [Function]
  4099. *standard-input*                [Variable]
  4100. *standard-output*               [Variable]
  4101. :start                          [Keyword]
  4102. :start1                         [Keyword]
  4103. :start2                         [Keyword]
  4104. :static                         [Keyword] Added.
  4105. step                            [Macro]
  4106. :stream                         [Keyword]
  4107. stream-element-type             [Function]
  4108. streamp                         [Function]
  4109. string                          [Function]
  4110. string-capitalize               [Function]
  4111. string-char-p                   [Function]
  4112. string-downcase                 [Function]
  4113. string-equal                    [Function]
  4114. string-greaterp                 [Function]
  4115. string-left-trim                [Function]
  4116. string-lessp                    [Function]
  4117. string-not-equal                [Function]
  4118. string-not-greaterp             [Function]
  4119. string-not-lessp                [Function]
  4120. string-right-trim               [Function]
  4121. string-trim                     [Function]
  4122. string-upcase                   [Function]
  4123. string/=                        [Function]
  4124. string<                         [Function]
  4125. string<=                        [Function]
  4126. string=                         [Function]
  4127. string>                         [Function]
  4128. string>=                        [Function]
  4129. stringp                         [Function]
  4130. sublis                          [Function]
  4131. subseq                          [Function]
  4132. subsetp                         [Function]
  4133. subst                           [Function]
  4134. subst-if                        [Function]
  4135. subst-if-not                    [Function]
  4136. substitute                      [Function]
  4137. substitute-if                   [Function]
  4138. substitute-if-not               [Function]
  4139. subtypep                        [Function]
  4140. :supersede                      [Keyword]
  4141. svref                           [Function]
  4142. sxhash                          [Function]
  4143. symbol-function                 [Function]
  4144. symbol-name                     [Function]
  4145. symbol-package                  [Function]
  4146. symbol-plist                    [Function]
  4147. symbol-value                    [Function]
  4148. symbolp                         [Function]
  4149. system                          [Function] Added.
  4150. t                               [Constant]
  4151. :tags                           [Keyword] Break Loop Command.
  4152. tagbody                         [Special]
  4153. tailp                           [Function]
  4154. tan                             [Function]
  4155. tanh                            [Function]
  4156. tenth                           [Function]
  4157. *terminal-io*                   [Variable] Different.
  4158. termination-message             [Function] Added.
  4159. terpri                          [Function]
  4160. :test                           [Keyword]
  4161. :test-not                       [Keyword]
  4162. the                             [Special]
  4163. third                           [Function]
  4164. throw                           [Special]
  4165. time                            [Macro]
  4166. trace                           [Macro]
  4167. *trace-output*                  [Variable]
  4168. tree-equal                      [Function]
  4169. truename                        [Function]
  4170. truncate                        [Function]
  4171. type                            [Symbol] Declaration Specifier.
  4172. :type                           [Keyword]
  4173. type-of                         [Function]
  4174. typecase                        [Macro]
  4175. typep                           [Function]
  4176. unexport                        [Function]
  4177. unintern                        [Function]
  4178. union                           [Function]
  4179. :unhide                         [Keyword] Break Loop Command.
  4180. :unhide-package                 [Keyword] Break Loop Command.
  4181. unless                          [Special, Macro]
  4182. unread-char                     [Function]
  4183. untrace                         [Macro]
  4184. unuse-package                   [Function]
  4185. unwind-protect                  [Special]
  4186. upper-case-p                    [Function]
  4187. use-package                     [Function]
  4188. user-homedir-pathname           [Function]
  4189. :username                       [Keyword] Added.
  4190. :v                              [Keyword] Abbreviated Break Loop Command.
  4191. values                          [Function]
  4192. values-list                     [Function]
  4193. :variables                      [Keyword] Break Loop Command.
  4194. vector                          [Function]
  4195. vector-pop                      [Function]
  4196. vector-push                     [Function]
  4197. vector-push-extend              [Function]
  4198. vectorp                         [Function]
  4199. :verbose                        [Keyword]
  4200. :version                        [Keyword]
  4201. warn                            [Function]
  4202. when                            [Special, Macro]
  4203. &whole                          [Symbol] Defmacro-lambda Keyword.
  4204. :wild                           [Keyword] Added.
  4205. with-input-from-string          [Macro]
  4206. with-open-file                  [Macro]
  4207. with-open-stream                [Macro]
  4208. with-output-to-string           [Macro]
  4209. write                           [Function]
  4210. write-byte                      [Function] Different.
  4211. write-char                      [Function]
  4212. write-line                      [Function]
  4213. write-string                    [Function]
  4214. write-to-string                 [Function]
  4215. y-or-n-p                        [Function]
  4216. yes-or-no-p                     [Function]
  4217. zerop                           [Function]
  4218.  
  4219.  
  4220.  
  4221.  
  4222.  
  4223.  
  4224.  
  4225.  
  4226.                     Appendix B. An Overview of Kyoto Common Lisp
  4227.  
  4228.  
  4229. Kyoto Common Lisp (KCL for short) is a full implementation of the Common
  4230. Lisp language.  KCL is a highly portable Common Lisp system intended for
  4231. several classes of machines, from mini/micro to mainframe.  The key idea
  4232. behind the portability is the use of the C language and its standard
  4233. libraries as the interface with the underlying machines and operating
  4234. systems:  The kernel of the system is written in C and the rest of the
  4235. system is written in Common Lisp.  Even the compiler generates intermediate
  4236. code in C.  KCL is also an efficient and compact system:  KCL regards the
  4237. runtime efficiency of interpreted code as important as the efficiency of
  4238. compiled code.  The small size of the KCL system makes KCL suitable for the
  4239. current computer technology, such as the use of virtual memory and cache
  4240. memory.  This document reports the current status of KCL, its
  4241. implementation, and system performance.  This document is a draft:  the
  4242. description is still incomplete and informal, and some technical terms are
  4243. used without definition or explanation.  A full paper on the KCL
  4244. implementation is in preparation.
  4245.  
  4246.  
  4247. KCL is a full Common Lisp system.
  4248.  
  4249. KCL is a full implementation of the Common Lisp language described in
  4250. the Common Lisp Reference Manual:
  4251.  
  4252.  
  4253.                  Common Lisp: The Language.
  4254.                  by Guy L. Steele et al.
  4255.                  Digital Press, 1984
  4256.  
  4257. KCL supports all Common Lisp functions, macros, and special forms defined
  4258. in the Common Lisp Reference Manual.  All Common Lisp variables and
  4259. constants are defined in KCL exactly as described in the Common Lisp
  4260. Reference Manual.
  4261.  
  4262.  
  4263.  
  4264. KCL is available on several machines already.
  4265.  
  4266. Currently, there are four major versions of KCL:
  4267.  
  4268.         1. KCL/AOS 
  4269.            Machine: Data General's Eclipse MV series super-minicomputers 
  4270.            (MV10000, MV8000, MV6000, and MV4000)
  4271.            Operating System: Data General's original AOS/VS 
  4272.            (Advanced Operating System / Virtual Storage)
  4273.  
  4274.         2. KCL/VAX
  4275.            Machine: Digital Equipment Corporation's VAX 11 
  4276.            series machines (VAX 11/780 and VAX 11/750)
  4277.            Operating System: UNIX 4.2 bsd
  4278.  
  4279.         3. KCL/SUN
  4280.            Machine: Sun Microsystems' Sun Workstation (MC68000 base)
  4281.            Operating System: UNIX 4.2 bsd
  4282.  
  4283.         4. KCL/UST
  4284.            Machine: Sumitomo Electric Industries and Digital 
  4285.            Computer Laboratory's personal workstation Ustation E15 
  4286.            (MC68000 base) 
  4287.            Operating System: UNIX V (Uniplus' version)
  4288.  
  4289. KCL/AOS is the original version of KCL, which was developed at Research
  4290. Institute for Mathematical Sciences (RIMS), Kyoto University, with the
  4291. cooperation of Nippon Data General Corporation.  Other versions are ported
  4292. from KCL/AOS at RIMS.  All four versions share most of the source files of
  4293. KCL.  Improvements and error corrections are performed on the common source
  4294. files, and the most recent revisions are brought to each machine from time
  4295. to time.
  4296.  
  4297. Ports to other machines and other operating systems are being undertaken or
  4298. are in preparation at other organizations.  KCL is expected to become
  4299. available on the following machines in the near future.
  4300.  
  4301.         * IBM (and IBM-compatible) M series machines
  4302.         * Apollo Domain
  4303.         * Perkins Elmer
  4304.         * VAX 11 (running VMS)
  4305.         * VAX 11 (running Eunice, the Unix emulator)
  4306.         * Eclipse MV (running DGUX, Data General's native Unix)
  4307.  
  4308.  
  4309. KCL is written in C and Lisp
  4310.  
  4311. The kernel of KCL is written in C, including:
  4312.  
  4313.         * memory management and garbage collection
  4314.         * the evaluator (or interpreter)
  4315.         * Common Lisp special forms
  4316.  
  4317. The KCL compiler is entirely written in Common Lisp.
  4318.  
  4319. Each Common Lisp function or macro is written either in C or in Lisp.
  4320.  
  4321.         in C:
  4322.                 418 Common Lisp functions
  4323.                 11 Common Lisp macros
  4324.  
  4325.         in Lisp:
  4326.                 133 Common Lisp functions
  4327.                 59 Common Lisp macros
  4328.  
  4329. The size of the source code is:
  4330.  
  4331.         C code           705 Kbytes
  4332.         Common Lisp functions and macros written in Lisp
  4333.                          173 Kbytes
  4334.         The compiler     264 Kbytes
  4335.         -------------------------
  4336.                 total   1142 Kbytes
  4337.  
  4338. Three routines in the kernel are partly written in assembly language.
  4339. These routines are:
  4340.  
  4341.         * bignum multiplication
  4342.         * bignum division
  4343.         * bit table manipulation of the garbage collector
  4344.  
  4345. The total size of assembly code is 20 to 30 lines, depending on the version
  4346. of KCL.
  4347.  
  4348.  
  4349.  
  4350. KCL/AOS is built up by old-fashioned bootstrapping
  4351.  
  4352. When KCL/AOS, the original version of KCL, was born, the following steps
  4353. were taken to build it up.
  4354.  
  4355.         1. Compile all C code with the C compiler and link them all.  A
  4356. subset of KCL is ready to run at this moment.
  4357.  
  4358.         2. Load all Lisp code into KCL.  Now the full system is ready to
  4359. run, although the compiler and some Common Lisp functions and macros run
  4360. interpretively.
  4361.  
  4362.         3. Compile the source files of the KCL compiler with the
  4363. (interpreted) KCL compiler itself.  Load each Fasl-file (i.e., the file
  4364. created by the KCL compiler) immediately after it is generated.  The
  4365. compilation process becomes faster toward the end of this step.  Finally,
  4366. the whole KCL compiler is ready to run by itself.
  4367.  
  4368.         4. Compile the Common Lisp functions and macros written in Lisp,
  4369. with the compiled KCL compiler.  Load the Fasl-files.  This completes the
  4370. generation of the full system.
  4371.  
  4372. The same steps are taken whenever drastic changes are made to the kernel.
  4373. On the other hand, the procedure to port KCL or to revise the ported
  4374. versions of KCL is much simpler, because all Lisp code has been
  4375. cross-compiled by the compiler of KCL/AOS beforehand.
  4376.  
  4377. Objects are represented by cells.
  4378.  
  4379. KCL does not support the so-called immediate data.  Any KCL object is
  4380. represented as (a pointer to) a cell that is allocated on the heap.  Each
  4381. cell consists of several words (1 word = 32 bit) whose first word is in the
  4382. format common to all data types: half of the word is the type indicator and
  4383. the other half is used as the mark by the garbage collector.  For instance,
  4384. a cons cell consists of three words:
  4385.  
  4386.                 ------------------------
  4387.                 |  'CONS'  |  mark-bit |
  4388.                 ------------------------
  4389.                 |      car-pointer     |
  4390.                 ------------------------
  4391.                 |      cdr-pointer     |
  4392.                 ------------------------
  4393.  
  4394. and a fixnum cell consists of two words:
  4395.  
  4396.                 ------------------------
  4397.                 | 'FIXNUM' |  mark-bit |
  4398.                 ------------------------
  4399.                 |    fixnum-value      |
  4400.                 ------------------------
  4401.  
  4402. Array headers and compiled-function headers are represented in this way, and
  4403. array elements and compiled code are placed elsewhere.
  4404.  
  4405. Internally in compiled functions, certain Lisp objects may be represented
  4406. simply by their values.  For example, a fixnum object may be represented by
  4407. its fixnum value, and a character object may be represented by its
  4408. character code.
  4409.  
  4410. Cells of small fixnums ranging from -1024 to 1023 and cells of characters
  4411. are pre-allocated in fixed locations.  Thus, for example,
  4412.  
  4413.         (eq 1023 1023)
  4414.  
  4415. yields t, whereas
  4416.  
  4417.         (eq 1024 1024)
  4418.  
  4419. yields nil.
  4420.  
  4421.  
  4422.  
  4423. The heap is divided into pages.
  4424.  
  4425. The whole heap of KCL is divided into pages (1 page = 2048 bytes).  Each page
  4426. falls in one of the following classes:
  4427.  
  4428.         * pages that contain cells consisting of the same number of words
  4429.         * pages that contain binary data such as compiled function code
  4430.         * pages that contain relocatable data such as array elements
  4431.  
  4432. Free cells (i.e., those cells that are not used any more) consisting of the
  4433. same number of words are linked together to form a free list.  When a new
  4434. cell is requested, the first cell in the free list (if it is not empty) is
  4435. used and is removed from the list.  If the free list is empty, then the
  4436. garbage collector begins to run to collect unused cells.  If the new free
  4437. list is too short after the garbage collection, then new pages are
  4438. allocated dynamically.  Free binary data are also linked together in the
  4439. order of the size so that, when a binary datum is being allocated on the
  4440. heap, the smallest free area that is large enough to hold the binary datum
  4441. will be used.  Cell pages are never compactified.  Once a page is allocated
  4442. for cells with n words, the page is used for cells with n words only, even
  4443. after all the cells in the page become garbage.  The same rule holds for
  4444. binary pages.  In contrast, relocatable pages are sometimes compactified.
  4445. That is, each relocatable datum may be moved to another place.
  4446.  
  4447. The actual configuration of the KCL heap is:
  4448.  
  4449.   lower address                                             higher address
  4450.         ----------------------------------------------------------------
  4451.         |  cell pages and binary pages  |  hole  |  relocatable pages  |
  4452.         ----------------------------------------------------------------
  4453.  
  4454. There is a "hole" between the area for cell/binary pages and the area for
  4455. relocatable pages.  New pages are allocated in the hole for cell/binary
  4456. pages, whereas new relocatable pages are allocated by expanding the heap to
  4457. the higher address, i.e., to the right in this figure.  When the hole
  4458. becomes empty, the area for relocatable pages are shifted to the right to
  4459. reserve a certain number of pages as the hole.  During this process, the
  4460. relocatable data in the relocatable pages are compactified.  No free list
  4461. is maintained for relocatable data.
  4462.  
  4463. Symbol print names and string bodies are usually allocated in relocatable
  4464. pages.  However, when the KCL system is created, i.e., when the object
  4465. module of KCL is created, such relocatable data are moved towards the area
  4466. for cell/binary pages and then the pages for relocatable data are marked
  4467. "static".  The garbage collector never tries to sweep static pages.  Thus,
  4468. within the object module of KCL, the heap looks like:
  4469.  
  4470.   lower address                        higher address
  4471.         ----------------------------------------
  4472.         |  cell/binary pages and static pages  |
  4473.         ----------------------------------------
  4474.  
  4475. Notice that the hole is not included in the object module; it is allocated
  4476. only when the KCL system is started.  This saves secondary storage
  4477. a little bit.  The maximum size of the hole is about
  4478. 100 pages (= 200 Kbytes).
  4479.  
  4480.  
  4481.  
  4482. KCL uses five stacks.
  4483.  
  4484. KCL uses the following stacks.
  4485.  
  4486.         * Value Stack, for
  4487.              arguments/values passing
  4488.              lexical variables allocation
  4489.              temporary values saving
  4490.  
  4491.         * Frame Stack, consisting of
  4492.              catch, block, tagbody frames
  4493.  
  4494.         * Bind Stack, for
  4495.              shallow binding of dynamic variables
  4496.  
  4497.         * Invocation History Stack, maintaining
  4498.              information for debugging
  4499.  
  4500.         * C Language Control Stack, sometimes used in compiled functions for:
  4501.              arguments/values passing
  4502.              typed lexical variables allocation
  4503.              temporary values saving,
  4504.           in addition to the obvious use such as function invocation
  4505.  
  4506.  
  4507. Arguments/values are passed via the value stack.
  4508.  
  4509. To show the argument/value passing mechanism, here we list the actual code
  4510. for the Common Lisp function cons.
  4511.  
  4512.         Lcons()
  4513.         {
  4514.                 object x;
  4515.                 check_arg(2);
  4516.                 x = alloc_object(t_cons);
  4517.                 x->c.c_car = vs_base[0];
  4518.                 x->c.c_cdr = vs_base[1];
  4519.                 vs_base[0] = x;
  4520.                 vs_pop;
  4521.         }
  4522.  
  4523. We adopted the convention that the name of a function that implements a
  4524. Common Lisp function begins with 'L', followed by the name of the Common
  4525. Lisp function.  (Strictly speaking, '-' and '*' in the Common Lisp function
  4526. name are replaced by '_' and 'A', respectively, to obey the syntax of C.)
  4527. Arguments to functions are pushed on the value stack.  The stack pointer
  4528. vs_base (value stack base) points to the first argument and another pointer
  4529. vs_top points to the stack location next to the last argument.  Thus, for
  4530. example, when cons is called with the first argument 1 and the second
  4531. argument 2, the value stack looks like:
  4532.  
  4533.                   4---------6
  4534.          vs_top ->|         |
  4535.                   -----------
  4536.                   |    2    |
  4537.                   -----------
  4538.         vs_base ->|    1    |
  4539.                   -----------
  4540.                   |         |
  4541.                   :         :
  4542.                   |         |
  4543.           bottom  -----------
  4544.                   value stack
  4545.  
  4546. check_arg(2) in the code of Lcons checks if exactly two arguments are
  4547. supplied to cons.  That is, it checks whether the difference of vs_top and
  4548. vs_base is 2, and if not, it causes an error.  allocate_object(t_cons)
  4549. allocates a cons cell in the heap and returns the pointer to the cell.
  4550. After the car and the cdr fields of the cell are set, the cell pointer is
  4551. put onto the value stack.  The two stack pointers are used also on return
  4552. from a function call.  vs_base points to the first returned value and
  4553. vs_top points to the stack location next to the last returned value.
  4554. vs_pop in the code above decrements vs_top by one.
  4555.  
  4556.                   4---------6
  4557.                   |         |
  4558.                   -----------
  4559.          vs_top ->|         |
  4560.                   -----------
  4561.         vs_base ->| (1 . 2) |
  4562.                   -----------
  4563.                   |         |
  4564.                   :         :
  4565.                   |         |
  4566.           bottom  -----------
  4567.                   value stack
  4568.  
  4569. Because the same stack pointers are used both for argument passing and for
  4570. return value passing, the Common Lisp function values does almost nothing.
  4571.  
  4572.         On the call of (values 1 2)    On return from (values 1 2)
  4573.  
  4574.                   -----------                -----------
  4575.          vs_top ->|         |       vs_top ->|         |
  4576.                   -----------                -----------
  4577.                   |    2    |                |    2    |
  4578.                   -----------                -----------
  4579.         vs_base ->|    1    |      vs_base ->|    1    |
  4580.                   -----------                -----------
  4581.                   |         |                |         |
  4582.                   :         :                :         :
  4583.                   |         |                |         |
  4584.           bottom  -----------        bottom  -----------
  4585.                   value stack                 value stack
  4586.  
  4587. In most cases, the caller of a function uses only the first returned value
  4588. which is pointed to by vs_base.  This is not the case, however, when the
  4589. called function returns no value at all.  In order to avoid the check
  4590. whether this is the case, each KCL function, on return from its call, sets
  4591. nil to the stack entry which is pointed to by vs_base, whenever it returns
  4592. no value at all.  Thus, for instance, the actual code for the Common Lisp
  4593. function values is:
  4594.  
  4595.         Lvalues()
  4596.         {
  4597.                 vs_top[0] = Cnil;
  4598.         }
  4599.  
  4600. where Cnil is a global variable that always contains the pointer to nil.
  4601. See why this works.
  4602.  
  4603.  
  4604.  
  4605. The interpreter uses A-lists.
  4606.  
  4607. The KCL interpreter uses three A-lists (Association lists) to represent
  4608. lexical environments.
  4609.  
  4610.         * One for variable bindings
  4611.         * One for local function/macro definitions
  4612.         * One for tag/block bindings
  4613.  
  4614. When a function closure is created, the current three A-lists are saved in
  4615. the closure along with the lambda expression.  Later, when the closure is
  4616. invoked, the saved A-lists are used to recover the lexical environment.
  4617.  
  4618.  
  4619.  
  4620. The invocation history stack is used for debugging.
  4621.  
  4622. The invocation history stack consists of two kinds of elements.  Each
  4623. element may be either a pair of a Lisp form and a pointer to lexical
  4624. environment:
  4625.  
  4626.         ---------------------------------------------
  4627.         |        form         | environment-pointer |
  4628.         ---------------------------------------------
  4629.  
  4630. or a pair of a function name and a pointer to the value stack:
  4631.  
  4632.         ---------------------------------------------
  4633.         |    function-name    | value-stack-pointer |
  4634.         ---------------------------------------------
  4635.  
  4636. The former is pushed on the invocation history stack when an interpreted
  4637. code is evaluated.  The form is the interpreted code itself and the
  4638. environment-pointer points to the three consecutive memory words each of
  4639. which holds the A-list that represents the lexical environment.  The latter
  4640. is pushed when a compiled function is invoked.  The function-name is the
  4641. name of the called function and the value-stack-pointer points to the value
  4642. stack location which is pointed to by vs_base when the function is called.
  4643. For both kinds, the element on the invocation history stack is poped at the
  4644. end of the evaluation.
  4645.  
  4646. Let us see how the invocation history stack is used for debugging.
  4647.  
  4648.         >(defun fact (x)                ;;; Wrong definition of the
  4649.            (if (= x 0)                  ;;; factorial function.
  4650.                one                      ;;; one should be 1.
  4651.                (* x (fact (1- x)))))
  4652.         fact
  4653.         
  4654.         >(fact 3)                       ;;; Tries 3!
  4655.         
  4656.         Error: The variable ONE is unbound.
  4657.         Error signalled by IF.
  4658.         
  4659.         Broken at IF.
  4660.         >>:b                            ;;; Backtrace.
  4661.         Backtrace: eval > fact > if > fact > if > fact > if > fact > IF
  4662.                                         ;;; Currently at the last if.
  4663.         >>:h                            ;;; Help.
  4664.  
  4665.         :c(urrent)      Show current function.
  4666.         :p(revious)     Move to previous function.
  4667.         :n(ext)         Move to next function.
  4668.         :b(acktrace)    Backtrace.
  4669.         :h(elp)         Help.
  4670.         :q(uit)         Return to top-level.
  4671.         :r(esume)       Return to the caller
  4672.         :l(ocal)        Show n-th local value.
  4673.         :v(ariables)    Show local variables.
  4674.         :functions      Show local functions.
  4675.         :blocks         Show block names.
  4676.         :tags           Show tags.
  4677.         :hide           Hide a function
  4678.         :hide-package   Hide a package.
  4679.         :unhide         Unhide a function
  4680.         :unhide-package Unhide a package.
  4681.  
  4682.         >>:p                            ;;; Move to the last call of fact.
  4683.         Broken at FACT.
  4684.         
  4685.         >>:b
  4686.         Backtrace: eval > fact > if > fact > if > fact > if > FACT > if
  4687.                                         ;;; Now at the last fact.
  4688.         >>:v                            ;;; The environment at the last call
  4689.         Local variables: x.             ;;; to fact is recovered.
  4690.                                         ;;; x is the only bound variable.
  4691.         >>x
  4692.         0                               ;;; The value of x is 0.
  4693.         
  4694.         >>:blocks
  4695.         Block names: fact.              ;;; The block fact is established.
  4696.         
  4697.         >>(return-from fact 1)          ;;; Return from the last call of
  4698.         6                               ;;; fact with value of 0.
  4699.                                         ;;; The execution is resumed and
  4700.         >                               ;;; the value 6 is returned.
  4701.                                         ;;; Again at the top-level loop.
  4702.  
  4703. The KCL compiler generates intermediate code in C.
  4704.  
  4705. The KCL compiler is essentially a translator from Common Lisp to C.  Given
  4706. a Lisp source file, the compiler first generates three intermediate files:
  4707.  
  4708.         * a C-file which consists of the C version of the Lisp program
  4709.         * an H-file which consists of declarations referenced in the C-file
  4710.         * a Data-file which consists of Lisp data to be used at load time
  4711.  
  4712. The KCL compiler then invokes the C compiler to compile the C-file into an
  4713. object file.  Finally, the contents of the Data-file is appended to the
  4714. object file to make a Fasl-file.  The generated Fasl-file can be loaded
  4715. into the KCL system by the Common Lisp function load.  By default, the
  4716. three intermediate files are deleted after the compilation, but, if asked,
  4717. the compiler leaves them.
  4718.  
  4719. The merits of the use of C as the intermediate language are:
  4720.  
  4721.         * The KCL compiler is highly portable.  Indeed the four versions of
  4722. KCL share the same compiler.  Only the calling sequence of the C compiler
  4723. and the handling of the intermediate files are different in these versions.
  4724.  
  4725.         * Cross compilation is possible, because the contents of the
  4726. intermediate files are common to all versions of KCL.  For example, one can
  4727. compile his or her Lisp program by the KCL compiler on Eclipse, bring the
  4728. intermediate files to SUN, compile the C-file with the C compiler on SUN,
  4729. and then append the Data-file to the object file.  This procedure generates
  4730. the Fasl-file for the KCL system on SUN.  This kind of cross compilation
  4731. makes it easier to port KCL.
  4732.  
  4733.         * Hardware-dependent optimizations such as register allocations are
  4734. done by the C compiler.
  4735.  
  4736. The demerits are:
  4737.  
  4738.         * At those sites where no C compiler is available, the users cannot
  4739. compile their Lisp programs.
  4740.  
  4741.         * The compilation time is long.  70% to 80% of the compilation time
  4742. is used by the C compiler.  The KCL compiler is perhaps the slowest
  4743. compiler in the Lisp world.
  4744.  
  4745. The compiler mimics human C programmer.
  4746.  
  4747. The format of the intermediate C code generated by the KCL compiler is the
  4748. same as the hand-coded C code of the KCL source programs.  For example,
  4749. supposing that the Lisp source file contains the following function
  4750. definition:
  4751.  
  4752.         (defun add1 (x) (1+ x))
  4753.  
  4754. The compiler generates the following intermediate C code.
  4755.  
  4756.         init_code(start,size,data)char *start;int size;object data;
  4757.         {       register object *base=vs_top;
  4758.                 register object *sup=base+VM2;
  4759.                 vs_check;
  4760.                 Cstart=start;Csize=size;Cdata=data;
  4761.                 set_VV(VV,VM1,data);
  4762.                 MF(VV[0],L1,start,size,data);
  4763.                 vs_top=vs_base=base;
  4764.         }
  4765.         /*      function definition for ADD1    */
  4766.         
  4767.         static L1()
  4768.         {       register object *base=vs_base;
  4769.                 register object *sup=base+VM3;
  4770.                 vs_reserve(VM3);
  4771.                 check_arg(1);
  4772.                 vs_top=sup;
  4773.                 base[1]=one_plus(base[0]);
  4774.                 vs_top=(vs_base=base+1)+1;
  4775.                 return;
  4776.         }
  4777.  
  4778. The C function L1 implements the Lisp function add1.  This relation is
  4779. established by MF in the initialization function init_code, which is
  4780. invoked at load time.  There, the vector VV consists of Lisp objects; VV[0]
  4781. in this example holds the Lisp symbol add1.  VM3 in the definition of L1 is
  4782. a C macro declared in the corresponding H-file.  The actual value of VM3 is
  4783. the number of value stack locations used by L1, i.e., 2 in this example.
  4784. Thus the following macro definition is found in the H-file.
  4785.  
  4786.         #define VM3 2
  4787.  
  4788. When the compiled add1 is called, the value stack looks like:
  4789.  
  4790.         On the call of (add1 1)    On return from (add1 1)
  4791.  
  4792.                   -----------                -----------
  4793.                   |         |       vs_top ->|         |
  4794.                   -----------                -----------
  4795.          vs_top ->|         |      vs_base ->|    2    |
  4796.                   -----------                -----------
  4797.         vs_base ->|    1    |                |    1    |
  4798.                   -----------                -----------
  4799.                   |         |                |         |
  4800.                   :         :                :         :
  4801.                   |         |                |         |
  4802.           bottom  -----------        bottom  -----------
  4803.                   value stack                 value stack
  4804.  
  4805. Note that the two value stack pointers need not be moved
  4806. in this example.  This shows that the KCL compiler still has room
  4807. for improvement.
  4808.  
  4809. Lexical environment of compiled closures is represented by a list.
  4810.  
  4811. The KCL compiler takes two passes before it invokes the C compiler.  The
  4812. major role of the first pass is to detect function closures and to detect,
  4813. for each function closure, those lexical objects (i.e., lexical variable,
  4814. local function definitions, tas, and block-names) to be enclosed within the
  4815. closure.  This check must be done before the C code generation in the
  4816. second pass, because lexical objects to be enclosed in function closures
  4817. are treated in a different way from those not enclosed.
  4818.  
  4819. Ordinarily, lexical variables in a compiled function f are allocated on the
  4820. value stack.  However, if a lexical variable is to be enclosed in function
  4821. closures, it is allocated on a list, called the "environment list", which
  4822. is local to f.  In addition, one entity is reserved on the value stack, in
  4823. which the pointer to the variable's location (within the environment list)
  4824. is stored, so that the variable may be accessed by indexing rather than by
  4825. list traversal.  The environment list is a pushdown list:  It is empty when
  4826. f is called.  An element is pushed on the environment list when a variable
  4827. to be enclosed in closures is bound, and is popped when the binding is no
  4828. more in effect.  That is, at any moment during execution of f, the
  4829. environment list contains those lexical variables whose binding is still in
  4830. effect and which should be enclosed in closures.  When a compiled closure
  4831. is created during execution of f, the compiled code for the closure is
  4832. coupled with the environment list at that moment to form the compiled
  4833. closure.  Later, when the compiled closure is invoked, as many entities as
  4834. the elements in the environment list is reserved on the value stack, each
  4835. of which points to a lexical object in the environment list, so that,
  4836. again, each object may be referenced by indexing.
  4837.  
  4838. Let us see an example.  Suppose the following function has been compiled.
  4839.  
  4840.         (defun foo (x)
  4841.           (let ((a #'(lambda () (incf x)))
  4842.                 (y x))
  4843.             (values a #'(lambda () (incf x y)))))
  4844.  
  4845. foo returns two compiled closures.  The first closure increments x by one,
  4846. whereas the second closure increments x by the initial value of x.  Both
  4847. closures return the incremented value of x.
  4848.  
  4849.         >(multiple-value-setq (f g) (foo 10))
  4850.         #<compiled-closure nil>
  4851.  
  4852.         >(funcall f)
  4853.         11
  4854.  
  4855.         >(funcall g)
  4856.         21
  4857.  
  4858.         >
  4859.  
  4860. After this, the two compiled closures look like:
  4861.  
  4862.         second closure        y:                    x:
  4863.         ----------------      ----------------      ---------------
  4864.         |  **   |    -------->|  10   |    -------->|  21  | nil  |
  4865.         ----------------      ----------------      ---------------
  4866.                                                         ^
  4867.                               first closure             |
  4868.                               ----------------          |
  4869.                               |   *   |    --------------
  4870.                               ----------------
  4871.  
  4872.    * : address of the compiled code for #'(lambda () (incf x))
  4873.   ** : address of the compiled code for #'(lambda () (incf x y))
  4874.  
  4875. Declarations increase code efficiency.
  4876.  
  4877. Declarations, especially type and function declarations, increase the
  4878. efficiency of the compiled code.  For example, for the following Lisp
  4879. source file, with two Common Lisp declarations added,
  4880.  
  4881.         (eval-when (compile)
  4882.           (proclaim '(function tak (fixnum fixnum fixnum) fixnum)))
  4883.  
  4884.         (defun tak (x y z)
  4885.           (declare (fixnum x y z))
  4886.           (if (not (< y x))
  4887.               z
  4888.               (tak (tak (1- x) y z)
  4889.                    (tak (1- y) z x)
  4890.                    (tak (1- z) x y))))
  4891.  
  4892. the compiler generates the following C code.
  4893.  
  4894.         /*  local entry for function TAK  */
  4895.         static int LI2(V4,V5,V6)
  4896.         int V4,V5,V6;
  4897.         {       VMB3 VMS3 VMV3
  4898.                 if((V5)<(V4)){
  4899.                 goto T4;}
  4900.                 VMR3(V6)
  4901.         T4:;
  4902.                 {int V7=LI2((V4)-1,V5,V6);
  4903.                 {int V8=LI2((V5)-1,V6,V4);
  4904.                 VMR3(LI2(V7,V8,LI2((V6)-1,V4,V5)))}}
  4905.         }
  4906.         /*  global entry for the function TAK  */
  4907.         static L2()
  4908.         {       register object *base=vs_base;
  4909.                 base[0]=make_fixnum(LI2(fix(base[0]),
  4910.                                         fix(base[1]),
  4911.                                         fix(base[2])));
  4912.                 vs_base=base; vs_top=base+1;
  4913.         }
  4914.  
  4915. The main part of the tak function is LI2.  If redundant parentheses are
  4916. removed, macros are expanded, and identifiers are renamed, we obtain the
  4917. following code equivalent to LI2.
  4918.  
  4919.         /*  local entry for function TAK  */
  4920.         static int tak(x,y,z)
  4921.         int x,y,z;
  4922.         {
  4923.                 if(y<x) goto L;
  4924.                 return(z);
  4925.         L:
  4926.                 {       int t1=tak(x-1,y,z);
  4927.                         int t2=tak(y-1,z,x);
  4928.                         return(tak(t1,t2,tak(z-1,x,y)));
  4929.                 }
  4930.         }
  4931.  
  4932. This is almost hand-written tak code in C.  The only overhead is the use of
  4933. the temporary variables t1 and t2.  This is necessary to make sure that the
  4934. arguments are evaluated in the correct order (i.e., from left to right),
  4935. since the C language does not specify the order of argument evaluation.  If
  4936. the compiler generated the following code,
  4937.  
  4938.         return(tak(tak(x-1,y,z),tak(y-1,z,x),tak(z-1,x,y)));
  4939.  
  4940. the C compiler of Eclipse AOS/VS evaluates the three inner calls to tak
  4941. from left to right (this is all right), whereas the C compiler of Unix
  4942. evaluates from right to left (this is bad).  In this example of tak, the
  4943. order of evaluation does not matter actually, because tak causes no side
  4944. effects.  But the KCL compiler does not know that.  The KCL compiler still
  4945. has room for improvements.
  4946.  
  4947. KCL does not have "disassembler".
  4948.  
  4949. Common Lisp defines a function disassemble, which is supposed to
  4950. disassemble a compiled function and to display the assembler code.
  4951. According to the Common Lisp Reference Manual,
  4952.  
  4953.         This is primary useful for debugging the compiler, ..
  4954.  
  4955. This is, however, useless in our case, because we are not concerned with
  4956. assembly language.  Rather, we are interested in the C code generated by
  4957. the KCL compiler.  Thus the disassemble function in KCL accepts
  4958. not-yet-compiled functions only and displays the translated C code.
  4959.  
  4960.         >(defun add1 (x) (1+ x))
  4961.         add1
  4962.         
  4963.         >(disassemble 'add1)
  4964.         init_code(start,size,data)char *start;int size;object data;
  4965.         {       register object *base=vs_top;
  4966.                 register object *sup=base+VM2;
  4967.                 vs_check;
  4968.                 Cstart=start;Csize=size;Cdata=data;set_VV(VV,VM1,data);
  4969.                 MF(VV[0],L1,start,size,data);
  4970.                 vs_top=vs_base=base;
  4971.         }
  4972.         /*      function definition for ADD1    */
  4973.         
  4974.         static L1()
  4975.         {       register object *base=vs_base;
  4976.                 register object *sup=base+VM3;
  4977.                 vs_check;
  4978.                 vs_top=sup;
  4979.                 base[1]=one_plus(base[0]);
  4980.                 vs_top=(vs_base=base+1)+1;
  4981.                 return;
  4982.         }
  4983.         
  4984.         >
  4985.  
  4986. KCL/AOS has its own screen editor.
  4987.  
  4988. KCL/AOS has an embedded full-screen editor which resembles EMACS.  The
  4989. editor is called FeCl2 as the acronym of Full-screen Editor as a Common
  4990. Lisp TOOl.  It is invoked by the Common Lisp function ed.  Unfortunately,
  4991. FeCl2 is not supported by other versions of KCL, simply because we are too
  4992. lazy to port it (it is written in C).  For these versions, ed invokes the
  4993. vi editor of Unix.
  4994.  
  4995. KCL has C language interface.
  4996.  
  4997. The user can embed his or her own C code into Lisp source code.  The idea
  4998. is very simple:  The specified C code is inserted in the intermediate C
  4999. code that is generated by the KCL compiler.  In the following example,
  5000. Clines and defentry are top-level macros specific to KCL.  The Clines macro
  5001. form specifies the C code to be embedded, in terms of strings, and the
  5002. defentry form defines an entry of the specified C function from KCL.
  5003.  
  5004.         (Clines
  5005.         "   int tak(x, y, z)                       "
  5006.         "   int x, y, z;                           "
  5007.         "   {   if (y >= x) return(z);             "
  5008.         "       else return(tak(tak(x-1, y, z),    "
  5009.         "                       tak(y-1, z, x),    "
  5010.         "                       tak(z-1, x, y)));  "
  5011.         "   }                                      "
  5012.         )
  5013.  
  5014.         (defentry tak (int int int) (int "tak"))
  5015.  
  5016. Port to VAX took three days.
  5017.  
  5018. Although KCL is made to be highly portable, certain minor changes had to
  5019. be done, when it was ported to VAX Unix 4.2 bsd.  These changes include:
  5020.  
  5021.         1. The compiler top-level was slightly changed, because of
  5022. the differences of the calling sequence of the C compiler and of the handling
  5023. of object files.
  5024.  
  5025.         2. File system interface was changed to fit Unix 4.2 bsd.
  5026.  
  5027.         3. The following system parameters were redefined because
  5028. Vax's representation of floating point numbers differs from that of Eclipse.
  5029.  
  5030.                 most-positive-short-float
  5031.                 most-negative-short-float
  5032.                 least-positive-short-float
  5033.                 least-negative-short-float
  5034.                 most-positive-long-float
  5035.                 most-positive-double-float
  5036.                 most-positive-single-float
  5037.                 most-negative-long-float
  5038.                 most-negative-double-float
  5039.                 most-negative-single-float
  5040.                 least-positive-long-float
  5041.                 least-positive-double-float
  5042.                 least-positive-single-float
  5043.                 least-negative-long-float
  5044.                 least-negative-double-float
  5045.                 least-negative-single-float
  5046.                 short-float-epsilon
  5047.                 short-float-negative-epsilon
  5048.                 long-float-epsilon
  5049.                 double-float-epsilon
  5050.                 single-float-epsilon
  5051.                 long-float-negative-epsilon
  5052.                 double-float-negative-epsilon
  5053.                 single-float-negative-epsilon
  5054.  
  5055.         4. For the same reason as above, the following machine-dependent
  5056. Common Lisp functions were rewritten.
  5057.  
  5058.                 decode-float
  5059.                 scale-float
  5060.                 float-radix
  5061.                 float-digits
  5062.                 float-precision
  5063.                 integer-decode-float
  5064.  
  5065.         5. The three assembler routines were rewritten.
  5066.  
  5067.         6. The in-core loader that loads Fasl-files into the KCL memory was
  5068. changed.  This was a simple job because we used the standard linkage editor
  5069. ld of Unix.
  5070.  
  5071.         7. The memory dump routine was rewritten.
  5072.  
  5073. The whole job of poring KCL to VAX Unix 4.2 bsd took three days.  Later, we
  5074. spent some more days, to fix bugs in the ported version of KCL.
  5075.  
  5076. Port to SUN took three evenings.
  5077.  
  5078. The port to the SUN Workstation was much easier than the port to the VAX,
  5079. mainly because the operating system is the same for both VAX and SUN.
  5080.  
  5081.         1. The compiler top-level of KCL/VAX was used without changes.
  5082.  
  5083.         2. The file system of KCL/VAX was used without changes.
  5084.  
  5085.         3. The system parameters that depend on the representation of
  5086. floating point numbers were rewritten.
  5087.  
  5088.         4. The Common Lisp functions that depend on the representation of
  5089. floating point numbers were redefined.
  5090.  
  5091.         5. The three assembler routines were rewritten.
  5092.  
  5093.         6. The in-core loader of KCL/VAX was used without changes.
  5094.  
  5095.         7. The memory dump routines of KCL/VAX was used without changes.
  5096.  
  5097. The whole job of poring KCL to SUN took three evenings.  Most of
  5098. the time was spent for the three assembler routines, because we did not know
  5099. anything about the MC68000 assembler at first.
  5100.  
  5101.  
  5102.  
  5103. Port to Ustation took one week.
  5104.  
  5105. The port to the Ustation was relatively a hard job.  It took almost a week.
  5106. The major difficulity was that the C compiler of Unix V on the Ustation
  5107. recognized identifiers only by the first seven characters.  As already
  5108. mentioned, we used the convention that the C function that implements the
  5109. Common Lisp function function-name is given the name Lfunction-name.  Thus,
  5110. for example, the Common Lisp functions on packages such as
  5111.  
  5112.                 package-name
  5113.                 package-nickname
  5114.                 package-shadowing-symbols
  5115.                 package-use-list
  5116.                 package-used-by-list
  5117.                 packagep
  5118.  
  5119. are implemented by the C functions whose names all begin with Lpackage.
  5120. These C functions are regarded as having the same name by the C compiler.
  5121. This problem was solved by preparing a preprocessor program which maps long
  5122. identifiers into smaller ones.  This program is now used by the KCL
  5123. compiler on Ustation before the C compiler is called.
  5124.  
  5125. KCL is relatively compact.
  5126.  
  5127. The size of the object module of the whole KCL system (including the Compiler)
  5128. is:
  5129.  
  5130.                 KCL/AOS         1.78 Mbytes
  5131.                 KCL/VAX         1.45 Mbytes
  5132.                 KCL/SUN         1.56 Mbytes
  5133.                 KCL/UST         1.56 Mbytes
  5134.  
  5135. Since all system initialization (such as loading the database of the KCL
  5136. compiler) has been done when the object module is created, the object
  5137. module size roughly corresponds to the initial size of the KCL process when
  5138. a KCL session is started, minus the initial size of the hole in the heap
  5139. (about 200 Kbytes).
  5140.  
  5141. Gabriel's benchmark.
  5142.  
  5143. The following table shows the results of Richard Gabriel's Lisp benchmark
  5144. tests with the four versions of KCL.  The results with five other Common
  5145. Lisp systems are also listed for comparison.  Each number represents the
  5146. CPU time (in seconds) for the compiled program.  '*' indicates that the
  5147. time includes garbage-collection time.  The data of S-1 Lisp and Spice Lisp
  5148. are found in:
  5149.  
  5150.  
  5151.                   Performance and Evaluation of Lisp Systems
  5152.                                     by
  5153.                             Richard  P. Gabriel
  5154.                     Computer Systems Ser. Research Reports,
  5155.                              MIT Press, 1985
  5156.  
  5157. We received the data of Symbolics, DEC Common Lisp, and DG Common Lisp
  5158. directly from Dr. Richard Gabriel in April 1985.  We measured the
  5159. data for KCL in July 1985.  For the details of the benchmark
  5160. tests, refer to the book above.
  5161.  
  5162.  
  5163.  
  5164.  Benchmark |   Boyer  |  Browse  | Destruct | Traverse | Traverse |
  5165.    Test    |          |          |          |Initialize|    Run   |
  5166.  -------------------------------------------------------------------
  5167.            |          |          |          |          |          |
  5168.   Kyoto CL |   11.02  |   18.09  |    3.15  |    5.75  |   44.16  |
  5169.    MV10000 |          |          |          |          |          |
  5170.            |          |          |          |          |          |
  5171.   Kyoto CL |   43.73  |   68.15* |    8.00  |   14.42  |  151.20  |
  5172.    VAX 780 |          |          |          |          |          |
  5173.            |          |          |          |          |          |
  5174.   Kyoto CL |   43.60* |   73.08* |   10.23  |   20.38  |  118.60  |
  5175.     E15    |          |          |          |          |          |
  5176.            |          |          |          |          |          |
  5177.   Kyoto CL |   47.00  |   81.37  |   14.10  |   26.30  |  160.58  |
  5178.     SUN    |          |          |          |          |          |
  5179.            |          |          |          |          |          |
  5180.  Symbolics |   11.99  |   30.8   |    3.03  |    8.62  |   49.95  |
  5181.    3600    |          |          |          |          |          |
  5182.            |          |          |          |          |          |
  5183.   S-1 CL   |   10.03  |   10.2   |    0.91  |    1.93  |   30.1   |
  5184.   Mark IIA |          |          |          |          |          |
  5185.            |          |          |          |          |          |
  5186.    Spice   |  134.79  |  359.63  |   17.78  |   41.75  |  490.6   |
  5187.     Perq   |          |          |          |          |          |
  5188.            |          |          |          |          |          |
  5189.    DEC CL  |   46.79  |  118.51  |    6.38  |   20.76  |  161.68  |
  5190.   VAX 780  |          |          |          |          |          |
  5191.            |          |          |          |          |          |
  5192.     DG CL  |   29.3   |   59.91  |    6.95  |   27.77  |   45.86  |
  5193.    MV10000 |          |          |          |          |          |
  5194.  
  5195.  
  5196.  
  5197.  Benchmark |    Tak   |   Stak   |   Ctak   |   Takl   |   Takr   |
  5198.    Test    |          |          |          |          |          |
  5199.  -------------------------------------------------------------------
  5200.            |          |          |          |          |          |
  5201.   Kyoto CL |    0.42  |    1.90  |    4.35  |    5.13  |    0.54  |
  5202.    MV10000 |          |          |          |          |          |
  5203.            |          |          |          |          |          |
  5204.   Kyoto CL |    1.45  |    6.03  |   14.02  |   19.97  |    1.75  |
  5205.    VAX 780 |          |          |          |          |          |
  5206.            |          |          |          |          |          |
  5207.   Kyoto CL |    1.17  |    7.63  |    9.58  |   16.10  |    1.38  |
  5208.     E15    |          |          |          |          |          |
  5209.            |          |          |          |          |          |
  5210.   Kyoto CL |    1.48  |   11.02  |   16.88  |   23.35  |    1.67  |
  5211.    SUN     |          |          |          |          |          |
  5212.            |          |          |          |          |          |
  5213.  Symbolics |    0.6   |    2.58  |    7.65  |    6.44  |    0.6   |
  5214.     3600   |          |          |          |          |          |
  5215.            |          |          |          |          |          |
  5216.    S-1 CL  |    0.29  |    4.31  |    0.82  |    2.92  |    0.58  |
  5217.   Mark IIA |          |          |          |          |          |
  5218.            |          |          |          |          |          |
  5219.    Spice   |    4.7   |   13.5   |    8.4   |   24.0   |    7.7   |
  5220.     Perq   |          |          |          |          |          |
  5221.            |          |          |          |          |          |
  5222.    DEC CL  |    1.83  |    4.11  |    8.09  |    7.34  |    3.42  |
  5223.    VAX 780 |          |          |          |          |          |
  5224.            |          |          |          |          |          |
  5225.     DG CL  |    0.89  |    3.09  |    1.79  |    5.52  |    1.21  |
  5226.    MV10000 |          |          |          |          |          |
  5227.  
  5228.  
  5229.  
  5230.  Benchmark |   Deriv  |  DDeriv  |   Div2   |   Div2   |    FFT   |
  5231.    Test    |          |          | Iterative| Recursive|          |
  5232.  -------------------------------------------------------------------
  5233.            |          |          |          |          |          |
  5234.   Kyoto CL |    4.85  |    5.93  |    1.99  |    2.73  |    1.55  |
  5235.    MV10000 |          |          |          |          |          |
  5236.            |          |          |          |          |          |
  5237.   Kyoto CL |   18.98  |   23.07  |    7.48  |   11.25  |    9.07  |
  5238.    VAX 780 |          |          |          |          |          |
  5239.            |          |          |          |          |          |
  5240.   Kyoto CL |   22.07* |   25.38* |    9.95* |   12.60* |   74.62  |
  5241.     E15    |          |          |          |          |          |
  5242.            |          |          |          |          |          |
  5243.   Kyoto CL |   20.72  |   24.77  |    9.32  |   12.30  |   94.07  |
  5244.     SUN    |          |          |          |          |          |
  5245.            |          |          |          |          |          |
  5246.  Symbolics |    5.12  |    5.24  |    1.85  |    2.89  |    4.75  |
  5247.     3600   |          |          |          |          |          |
  5248.            |          |          |          |          |          |
  5249.    S-1 CL  |    4.99  |    3.27  |    0.82  |    1.49  |    1.44  |
  5250.   Mark IIA |          |          |          |          |          |
  5251.            |          |          |          |          |          |
  5252.    Spice   |   71.8   |   77.7   |   28.15  |   40.69  |   59.0   |
  5253.     Perq   |          |          |          |          |          |
  5254.            |          |          |          |          |          |
  5255.    DEC CL  |   13.76  |   ---    |    5.0   |    9.84  |   32.69  |
  5256.    VAX 780 |          |          |          |          |          |
  5257.            |          |          |          |          |          |
  5258.     DG CL  |    5.6   |    8.11  |    2.86  |    4.48  |   62.78  |
  5259.    MV10000 |          |          |          |          |          |
  5260.  
  5261.  
  5262.  
  5263.  Benchmark |   Puzzle |  Triang  |  Fprint  |   Fread  |  Tprint  |
  5264.    Test    |          |          |          |          |          |
  5265.  -------------------------------------------------------------------
  5266.            |          |          |          |          |          |
  5267.   Kyoto CL |    6.76  |  104.85  |    1.98  |    2.45  |    1.74  |
  5268.    MV10000 |          |          |          |          |          |
  5269.            |          |          |          |          |          |
  5270.   Kyoto CL |   20.57  |  366.12  |    5.73  |    5.77  |    6.55  |
  5271.    VAX 780 |          |          |          |          |          |
  5272.            |          |          |          |          |          |
  5273.   Kyoto CL |   41.30  |  341.23* |    9.83  |    6.07  |   11.58  |
  5274.     E15    |          |          |          |          |          |
  5275.            |          |          |          |          |          |
  5276.   Kyoto CL |   49.13  |  499.68  |   10.05  |    7.62  |    8.50  |
  5277.     SUN    |          |          |          |          |          |
  5278.            |          |          |          |          |          |
  5279.  Symbolics |   13.89  |  151.7   |    2.6   |    4.6   |    4.9   |
  5280.     3600   |          |          |          |          |          |
  5281.            |          |          |          |          |          |
  5282.    S-1 CL  |    1.82  |   62.06  |   ---    |   ---    |   ---    |
  5283.   Mark IIA |          |          |          |          |          |
  5284.            |          |          |          |          |          |
  5285.    Spice   |   75.14  | 1488.85  |   20.0   |   26.0   |   22.6   |
  5286.     Perq   |          |          |          |          |          |
  5287.            |          |          |          |          |          |
  5288.    DEC CL  |   47.48  |  360.85  |    3.94  |    7.24  |    2.85  |
  5289.    VAX 780 |          |          |          |          |          |
  5290.            |          |          |          |          |          |
  5291.     DG CL  |  138.2   |  151.2   |    2.35  |    4.65  |    2.83  |
  5292.    MV10000 |          |          |          |          |          |
  5293.  
  5294.  
  5295.             Appendix C. Kyoto Common Lisp Installation Guide
  5296.  
  5297. This appendix explains how to install the KCL system, separately for each
  5298. version of KCL.
  5299.  
  5300. C.1. Installation of KCL/AOS
  5301.  
  5302. 1. Prepare a directory (hereafter called KCL directory) for Kyoto Common
  5303. Lisp.  In the following examples, we suppose that the KCL directory is
  5304. :UDD:KCL.
  5305.  
  5306.  
  5307. 2. Load the distribution tape to the KCL directory.
  5308.  
  5309.         ) DIR
  5310.         :UDD:KCL
  5311.         ) LOAD
  5312.  
  5313. You will find that the subdirectory PORT has been created.  The PORT
  5314. subdirectory contains everything that is needed to run KCL.  Files in this
  5315. directory are:
  5316.  
  5317.     Documents:
  5318.         README                  this file
  5319.  
  5320.     Executable files:
  5321.         KCL.PR                  the KCL interpreter and compiler
  5322.         KCL.ST
  5323.         BUILD_FASL.PR           the fasl-file builder
  5324.         FECL2.PR                the FeCl2 editor
  5325.  
  5326.     Command files:
  5327.         KCL.CLI                 to invoke KCL
  5328.         LC.CLI                  to invoke the KCL compiler
  5329.         LC1.CLI                 to invoke the KCL compiler
  5330.         FECL2.CLI               to invoke the FeCl2 editor
  5331.  
  5332.      Header file:
  5333.         CMPINCLUDE.H            the header file for the KCL compiler
  5334.  
  5335.      Miscellaneous:
  5336.         FECL2.CMD               FeCl2 editor command table
  5337.  
  5338. 3. Customize the command files.
  5339.  
  5340. The command file KCL.CLI consists of the following command lines to invoke
  5341. the KCL interpreter.
  5342.  
  5343.         push;prom pop
  5344.         sea :usr:dgc [!sea]
  5345.         x :udd:[!user]:port:%0-% :udd:[!user]:port:
  5346.         pop
  5347.  
  5348. Replace the two occurrences of "[!user]" with the name of the KCL directory
  5349. (i.e., KCL in our example).
  5350.  
  5351.         push;prom pop
  5352.         sea :usr:dgc [!sea]
  5353.         x :udd:KCL:port:%0-% :udd:KCL:port:
  5354.         pop
  5355.  
  5356. And move this file to an appropriate command directory, say :UTIL, so that
  5357. all KCL users can access it.
  5358.  
  5359. If the name of the directory that includes DG's C compiler is not :USR:DGC,
  5360. you should replace it with the appropriate directory name, so that the KCL
  5361. compiler can access the C compiler by CC.PR.
  5362.  
  5363. You can use the commands LC.CLI and LC1.CLI to invoke the compiler directly
  5364. from the CLI.  The content of LC.CLI is:
  5365.  
  5366.         push
  5367.          prompt pop level
  5368.          sea :usr:dgc [!sea]
  5369.          WRITE Compiling %1%.LSP.
  5370.           proc/def/ioc/block/pri=3 &
  5371.           :udd:[!user]:port:kcl :udd:[!user]:port: %1% %1% U10000
  5372.         pop
  5373.  
  5374. Customize these command files in the same way as for the KCL.CLI command
  5375. file above.
  5376.  
  5377. 4. Install the header file
  5378.  
  5379. Copy the header file CMPINCLUDE.H to the standard directory for C include
  5380. files, say :USR:DGC.
  5381.  
  5382. C.2. Installation of KCL/VAX
  5383.  
  5384. 1. Prepare a directory (hereafter called KCL directory) for Kyoto Common
  5385. Lisp.  In the following examples, we suppose that the KCL directory is
  5386. /usr/kcl.
  5387.  
  5388. 2. Load the distribution tape to the KCL directory.
  5389.  
  5390.         % pwd
  5391.         /usr/kcl
  5392.         % tar x
  5393.  
  5394. You will find that the subdirectory unixport has been created.  The
  5395. unixport subdirectory contains everything that is needed to run KCL and the
  5396. KCL compiler.  Files in this directory are:
  5397.  
  5398.     Documents:
  5399.         readme                  this file
  5400.  
  5401.     Executable files:
  5402.         saved_kcl               the KCL interpreter and compiler
  5403.  
  5404.     Command files:
  5405.         kcl                     to invoke KCL
  5406.         lc                      to invoke the KCL compiler
  5407.         lc1                     to invoke the KCL compiler
  5408.  
  5409.      Header file:
  5410.         cmpinclude.h            the header file for the KCL compiler
  5411.  
  5412. 3. Customize the command files.
  5413.  
  5414. The command file kcl consists of a single line command to invoke the KCL
  5415. interpreter.
  5416.  
  5417.         #
  5418.         ~/unixport/saved_kcl ~/unixport/
  5419.  
  5420. Replace two '~'s with the pathname of the KCL directory (i.e., 
  5421. /usr/kcl in our example).
  5422.  
  5423.         #
  5424.         /usr/kcl/unixport/saved_kcl /usr/kcl/unixport/
  5425.  
  5426. And move this file to an appropriate command directory, say /usr/bin, so
  5427. that all KCL users can access it.
  5428.  
  5429. You can use the commands lc and lc1 to invoke the compiler directly from
  5430. the shell.  The content of lc is:
  5431.  
  5432.         #
  5433.         echo Compiling $1.lsp
  5434.         ~/unixport/saved_kcl ~/unixport/ $1 $1 U1000
  5435.  
  5436. Customize these command files in the same way as for the kcl command file
  5437. above.
  5438.  
  5439. 4. Install the header file
  5440.  
  5441. Copy the header file cmpinclude.h to the standard directory for C include
  5442. files, say /usr/include.
  5443.  
  5444. C.3. Installation of KCL/SUN
  5445.  
  5446. 1. Prepare a directory (hereafter called KCL directory) for Kyoto Common
  5447. Lisp.  In the following examples, we suppose that the KCL directory is
  5448. /usr/kcl.
  5449.  
  5450. 2. Load the distribution tape to the KCL directory.
  5451.  
  5452.         % pwd
  5453.         /usr/kcl
  5454.         % tar x
  5455.  
  5456. You will find that the subdirectory unixport has been created.  The
  5457. unixport subdirectory contains everything that is needed to run KCL and the
  5458. KCL compiler.  Files in this directory are:
  5459.  
  5460.     Documents:
  5461.         readme                  this file
  5462.  
  5463.     Executable files:
  5464.         saved_kcl               the KCL interpreter and compiler
  5465.  
  5466.     Command files:
  5467.         kcl                     to invoke KCL
  5468.         lc                      to invoke the KCL compiler
  5469.         lc1                     to invoke the KCL compiler
  5470.  
  5471.      Header file:
  5472.         cmpinclude.h            the header file for the KCL compiler
  5473.  
  5474.  
  5475. 3. Customize the command files.
  5476.  
  5477. The command file kcl consists of a single line command to invoke the KCL
  5478. interpreter.
  5479.  
  5480.         #
  5481.         ~/unixport/saved_kcl ~/unixport/
  5482.  
  5483. Replace two '~'s with the pathname of the KCL directory (i.e., /usr/kcl in
  5484. our example).
  5485.  
  5486.         #
  5487.         /usr/kcl/unixport/saved_kcl /usr/kcl/unixport/
  5488.  
  5489. And move this file to an appropriate command directory, say /usr/bin, so
  5490. that all KCL users can access it.
  5491.  
  5492. You can use the commands lc and lc1 to invoke the compiler directly from the
  5493. shell.  The content of lc is:
  5494.  
  5495.         #
  5496.         echo Compiling $1.lsp
  5497.         ~/unixport/saved_kcl ~/unixport/ $1 $1 U1000
  5498.  
  5499. Customize these command files in the same way as for the kcl command file
  5500. above.
  5501.  
  5502.  
  5503. 4. Install the header file
  5504.  
  5505. Copy the header file cmpinclude.h to the standard directory for C include
  5506. files, say /usr/include.
  5507.  
  5508.  
  5509.  
  5510. C.4. Installation of KCL/UST
  5511.  
  5512.  
  5513. 1. Prepare a directory (hereafter called KCL directory) for Kyoto Common
  5514. Lisp.  In the following examples, we suppose that the KCL directory is
  5515. /usr/kcl.
  5516.  
  5517. 2. Three floppy disks are used for the distribution.  Load the floppy disks
  5518. to the KCL directory by the multi-volume option of the tar command.  (Insert
  5519. the first disk to the drive and issue the tar command.  Then, you will be
  5520. prompted to change the disks.)
  5521.  
  5522.         % pwd
  5523.         /usr/kcl
  5524.         % tar xvfBM /dev/rdy0g 1976
  5525.  
  5526. You will find that the subdirectory unixport has been created.  The unixport
  5527. subdirectory contains everything that is needed to run KCL and
  5528. the KCL compiler.  Files in this directory are:
  5529.  
  5530.     Documents:
  5531.         readme                  this file
  5532.  
  5533.     Executable files:
  5534.         saved_kcl               the KCL interpreter and compiler
  5535.         ild                     incremental loader
  5536.         trans                   translator from Unix 4.2 to Unix V
  5537.  
  5538.     Command Source files:
  5539.         kcl.c                   to invoke KCL
  5540.         lc.c                    to invoke the KCL compiler
  5541.         lc1.c                   to invoke the KCL compiler
  5542.  
  5543.      Header file:
  5544.         cmpinclude.h            the header file for the KCL compiler
  5545.  
  5546.  
  5547. 3. Customize the command files.
  5548.  
  5549. The source file kcl.c consists of a C-language program to invoke the KCL
  5550. interpreter.  Replace all /usr/ukcl in this file with the pathname of the
  5551. KCL directory (i.e., /usr/kcl in our example), and compile this file.
  5552.  
  5553.         % cc -o kcl kcl.c
  5554.  
  5555. And move the object file to an appropriate command directory, say /usr/bin,
  5556. so that all KCL users can access it.
  5557.  
  5558. You can use the source files lc.c and lc1.c to invoke the compiler directly
  5559. from the shell.  Customize these source files in the same way as for the
  5560. kcl command file above.
  5561.  
  5562.  
  5563. 4. Install the header file
  5564.  
  5565. Copy the header file cmpinclude.h to the standard directory for C include
  5566. files, say /usr/include.
  5567.  
  5568.  
  5569.  
  5570.  
  5571.                          Addendum, 1986
  5572.  
  5573.  
  5574.         KCL on UNIX: Problems and Future Improvement
  5575.  
  5576.  
  5577. * Core Dump
  5578.  
  5579. We can consider several situations in which KCL dumps core.
  5580.  
  5581. 1. The KCL compiler, by default, produces efficient but very dangerous
  5582. code.  The code seldom detects erraneous situations such as extracting the
  5583. car of a fixnum, which, in bad cases, cause "Segmentation violation" or
  5584. "Bus error" on UNIX.  I think this is the reason for most of the complaints
  5585. you have been reported so far.  To avoid this, one should tell the compiler
  5586. to produce rather inefficient but safe code using the appropriate
  5587. proclamation such as
  5588.  
  5589.         (proclaim '(optimize (safety 2))).
  5590.  
  5591. The safety level greater than or equal to 2 guarantees that the
  5592. code detects every runtime error.
  5593.  
  5594. 2. KCL keeps several stacks.  Whenever an item is pushed on a stack, KCL
  5595. checks whether the stack limit is violated or not, except for the value
  5596. stack and the C stack.  The limit for the value stack is not checked if the
  5597. code was compiled with the safety level 0; i.e., the limit is always
  5598. checked in the code compiled with the safety level greater than 0, and in
  5599. the interpreted code.
  5600.  
  5601. 3. The limit for the C stack is not checked in the compiled code.  We can
  5602. insert the code to check the C stack limit at the beginning of each
  5603. compiled function.  However, we don't think it is feasible.
  5604.  
  5605. 4. GC of KCL uses the C stack in the marking phase.  Currently, the C stack
  5606. overflow in the marking phase is not detected.  We will insert the code to
  5607. check the stack limit in the next revision.  However, we can't signal a
  5608. Lisp error in GC.  The C stack overflow in GC will result in a fatal error.
  5609.  
  5610. Note: Big lists extending to the direction of car consume more stack
  5611. area than those extending to cdr. 
  5612.  
  5613.  
  5614. * C Stack Limit
  5615.  
  5616. The C stack limit used by KCL is smaller than the actual limit.  Currently,
  5617. its value is fixed and independent of the actual limit.  On BSD, as you may
  5618. know, the actual limit for the C stack can be changed by the limit command
  5619. of csh.  In the next revision, we will set the C stack limit of KCL from
  5620. the value obtained by the getrlimit system call.  Therefore, for those
  5621. applications that use much stack area, one can invoke KCL in the following
  5622. way:
  5623.  
  5624.         % limit stacksize 1024          # 1024K bytes = 1M bytes
  5625.         % kcl
  5626.  
  5627. We can even change KCL so that it dynamically increments its C stack limit
  5628. by the setrlimit system call.  But we don't think it's feasible, either.
  5629.  
  5630. Note: Currently, the C stack limit of KCL is set 15000 words = 60K bytes
  5631. for all the versions of KCL.  Its value is defined as the C macro CSSIZE in
  5632. "h/eval.h".
  5633.  
  5634. Note: The actual stack limit is 512K by default on SUN-III.
  5635.  
  5636. Note: In the revision of KCL you have, the C stack overflow will never
  5637. signal a Lisp error; it always results in a fatal error and KCL terminates
  5638. immediately.  This is a BUG.  I found it while I was checking the behavior
  5639. of KCL for the C stack overflow.  I've already fixed it, so in the next
  5640. revision, the C stack overflow will signal a Lisp error except in GC.
  5641.  
  5642.  
  5643. * Process Size
  5644.  
  5645. Since KCL keeps a table which records the type of each page in the process
  5646. space, the process size of KCL is limited by the size of the table.  Its
  5647. size is determined by the MAXPAGE macro defined on the cc command line used
  5648. for compiling each C source file of KCL.  Currently, MAXPAGE = 16384 = 32M
  5649. bytes.  I think the size is reasonable now.
  5650.  
  5651. On BSD, the size of the KCL process is also limited by the resource limit
  5652. set by the limit command.  KCL doesn't change the limit by the setrlimit
  5653. system call.
  5654.  
  5655. Note: Even if the resource limit is 1G, you can't use that much unless
  5656. MAXPAGE is large enough.
  5657.  
  5658. Note: For SUN-III, the limit is nearly 256M bytes by default.
  5659.  
  5660. Note: Even if the resource limit is bigger than MAXPAGE, you can't use
  5661. MAXPAGE pages because of the limitation of the swap space of the operating
  5662. system.  In SUN3/75M, which I am using now, I can't allocate more than 16M.
  5663. If there are many other processes running, I can only allocate far less
  5664. than 16M.
  5665.  
  5666. * Explicit Expansion of Process Space
  5667.  
  5668. Usually, KCL expands its process space incrementally, i.e., it only
  5669. allocates memory after it has failed in collecting enough space by GC.  In
  5670. order to expands the process space of KCL explicitly, we changed the
  5671. function ALLOCATE and ALLOCATE-CONTIGUOUS-PAGES so that they take one
  5672. optional argument.  When a non-NIL value is supplied for the optional
  5673. argument, these functions acutally allocate the maximum number of pages for
  5674. the specified type or for the contiguous blocks.  Therefore, one can begin
  5675. with 1M bytes for conses (500 pages = 1M bytes) as follows:
  5676.  
  5677.         % kcl
  5678.         KCL (Kyoto Common Lisp) ...
  5679.  
  5680.         >(allocate 'cons 500 t)
  5681.         t
  5682.  
  5683.         >
  5684.  
  5685. If one extends the hole size by SI:SET-HOLE-SIZE and allocates memory as
  5686. above, while consuming the current hole, KCL will surely make the hole of
  5687. the specified size.  Therefore, if one begins KCL in the following way, one
  5688. will never invoke GC.
  5689.  
  5690.         % kcl
  5691.         KCL (Kyoto Common Lisp) ...
  5692.  
  5693.         >(si:set-hole-size 8000)        ; 16M
  5694.         8000
  5695.  
  5696.         >(allocate 'cons 500 t)         ; Actually allocates 1M.
  5697.                                         ; The hole will be 16M.
  5698.         t
  5699.  
  5700.         >(allocate 'cons 8000)          ; Set the maximum.
  5701.         t
  5702.  
  5703.         ...
  5704.         ...
  5705.  
  5706.         >(allocate 'fixnum 8000)
  5707.         t
  5708.  
  5709.         >(allocate-contiguous-pages 8000)
  5710.         t
  5711.  
  5712.         >(allocate-relocatable-pages 3000)      ; 6M
  5713.         t
  5714.  
  5715. Note: In the above example, KCL allocates 16M for cells and 6M for
  5716. relocatable blocks.  Since KCL uses two spaces for the relocatable area,
  5717. 16M + 2*6M < 32M.  We are not prepared for the critical case, say 16M+2*8M
  5718. = 32M.
  5719.  
  5720. Note: The above example will not work on SUN-III in general, unless you
  5721. reinstall the operating system so that it has MUCH swap space.  Please make
  5722. a test with smaller parameters than above, after you have recieved the next
  5723. revision of KCL.
  5724.  
  5725. Note: One should first check the size of the swap space before
  5726. complaining about KCL.
  5727.  
  5728. * Notification of GC
  5729.  
  5730. We defined a new system-internal variable SI:*NOTIFY-GBC*.  When
  5731. its value is non-NIL, GC will print
  5732.  
  5733.         GBC invoked
  5734.  
  5735. when it is invoked, and will print
  5736.  
  5737.         GBC finished
  5738.  
  5739. when it returns.  It's much neater than SI:*GBC-MESSAGE*.
  5740.  
  5741. Note: The message is directly written on the standard output of the C
  5742. library and is not written on a Lisp stream.  Therefore, when one DRIBBLEs
  5743. the KCL session, the message from GC won't be written out on the specified
  5744. file.  This is because writing on a stream has the danger of consuming
  5745. memory.
  5746.  
  5747.  
  5748. * Faslink
  5749.  
  5750. We made the loader which can load the object file while linking
  5751. other object files and/or libraries.  It is defined as a function
  5752. SI:FASLINK and used as follows:
  5753.  
  5754.         (si:faslink "foo.o" "bar.o boo.o -lpixrect")
  5755.  
  5756. "foo.o" should be an object file produced by compiling a Lisp source file.
  5757. The Lisp file, in general, consists of DEFENTRY definitions that call
  5758. functions in the object files and/or the libraries specified in the second
  5759. argument.  The first argument should be a pathname, a string or a symbol,
  5760. and the second argument should be a string that can be accpted by the UNIX
  5761. linkage editor.  If there are more than one arguments, they should be
  5762. separated by a space as above.
  5763.  
  5764. Note: The second argument is passed to "ld" as it is.
  5765.  
  5766. Note: SI:FASLINK is only defined in the BSD versions of KCL.
  5767.  
  5768.  
  5769. * valloc
  5770.  
  5771. The SunView library uses the "valloc" function of C.  To use the SunView
  5772. library with KCL, one should redefine "valloc" as follows:
  5773.  
  5774.         #define PAGSIZ  ...
  5775.  
  5776.         char *
  5777.         valloc(size)
  5778.         {
  5779.                 int p;
  5780.  
  5781.                 p = (int)malloc(size+PAGSIZ);
  5782.                 return((p+PAGSIZ-1)&(~PAGSIZ));
  5783.                 return((char *)p);
  5784.         }
  5785.  
  5786. Note: In my SunView interface, all the libraries are linked with KCL from
  5787. the beginning.  I haven't checked that SI:FASLINK will work for SunView.
  5788. But, it is necessary (perhaps, not sufficient) to redefine "valloc" as
  5789. above.
  5790.  
  5791.  
  5792. * init.lsp
  5793.  
  5794. If there exists a file with the name "init.lsp" in the current directory,
  5795. KCL loads the file before entering into the top-level loop.  The user of
  5796. KCL is expected to make his own environment using this facility.  It is
  5797. similar to ".chsrc" for csh, ".profile" for sh, ".newsrc" for readnews,
  5798. although the name doesn't begin with ".".
  5799.  
  5800. If you want to invoke your favorate editor from KCL, please define the
  5801. interface in "init.lsp".
  5802.  
  5803.  
  5804. * Big C Code
  5805.  
  5806. The C compiler sometimes complains that the code produced by KCL is too big
  5807. and cannot compute jump addresses.  I bet this is a bug of the UNIX
  5808. assembler.  To avoid this, one should supply the assembler with the -J
  5809. option.  I'm not sure that the cc command will pass the -J option to the
  5810. assembler, since it passes those arguments it can't interpret to the
  5811. linkage editor in general.
  5812.  
  5813. To avoid the problem, you should compile the Lisp file by
  5814.  
  5815.         >(compile-file "foo.lsp" :c-file t :h-file t :data-file t
  5816.                        :o-file nil)
  5817.  
  5818. and compile the C file with the -S option
  5819.  
  5820.         % cc -S foo.c
  5821.  
  5822. and then assemble it with the -J option.
  5823.  
  5824.         % as -J foo.s -o foo.o
  5825.  
  5826. Finally, on BSD, concatenate the data file at the end.
  5827.  
  5828.         % cat foo.data >> foo.o
  5829.  
  5830. Note: The above recipe is totally dependent on the version of UNIX.  I hope
  5831. you will report what C compilers (and assemblers) have failed in compiling
  5832. the C code produced by the KCL compiler.
  5833.